http://qs321.pair.com?node_id=1179883

scorpio17 has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to teach myself how to use Regexp::Common, and I'm having a little trouble.

The following works as expected, and finds the number 1234 embedded in the string aaaa1234cccc:

use strict; use Regexp::Common; while ( my $word = <DATA> ) { chomp $word; if ( $word =~ /$RE{num}{int}/ ) { print "Integer detected: \"$word\"\n"; } else { print "$word\n"; } } __DATA__ aaaabbbbcccc aaaa1234cccc ddddeeeeffff

However, this does NOT work as I would expect:

use strict; use Regexp::Common; while ( my $word = <DATA> ) { chomp $word; if ( $word =~ /$RE{profanity}/ ) { print "Profanity detected: \"$word\"\n"; } else { print "$word\n"; } } __DATA__ aaaabbbbcccc aaaaXXXXcccc ddddeeeeffff

In this case, change XXXX into your favorite 4 letter offensive word. If I change the data string to this: "aaaa XXXX cccc" (i.e., add spaces around the XXXX, then it finds it).

It seems like the profanity patterns have start of word / end of word anchors built into the patterns, and thus don't work if the word is embedded inside another string? Is there any way to control this behavior? I've gone through the docs, but so far I can't find a way.

I'm using perl 5.14 (activestate) on Win7. Thanks for any push in the right direction.