in reply to regex start of word (\<)
#!/usr/bin/perl use strict; use warnings; #885479 my $string = " cat mat rat pat\n"; if ($string =~ /\bcat/) { print "yes\n"; } else { print "no\n"; }
Note also the omission of your exit 0; and substitution of use warnings (scoped to the current script whereas - w may kick out warnings about any modules you might use in some more complex program.
However, for future posts, please enclose code (and data) in <c>...</c> tags. See Markup in the Monastery.
Updated with MRE citation.
|
|---|