in reply to Word boundary in regexp
See also Defining Characters in Word Boundary?.
Based on the suggestion in the first reply there:
my $string_to_check = "yyy foo-bar doo zzz"; my $set = '[\w-]'; my $b = qr/(?<=$set)(?!$set)|(?<!$set)(?=$set)/; for my $check ("foo-bar doo", "bar doo") { if ($string_to_check =~ /$b$check$b/) { print "$check matched\n"; } }
|
|---|