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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Please help with Regexp::Common
by LanX (Saint) on Jan 18, 2017 at 23:55 UTC | |
Re: Please help with Regexp::Common
by Paladin (Vicar) on Jan 18, 2017 at 23:52 UTC | |
by LanX (Saint) on Jan 19, 2017 at 00:28 UTC | |
Re: Please help with Regexp::Common
by AnomalousMonk (Archbishop) on Jan 19, 2017 at 00:01 UTC | |
by scorpio17 (Canon) on Jan 19, 2017 at 15:50 UTC | |
by AnomalousMonk (Archbishop) on Jan 19, 2017 at 18:11 UTC | |
by Mr. Muskrat (Canon) on Jan 19, 2017 at 16:14 UTC | |
by afoken (Chancellor) on Jan 19, 2017 at 18:38 UTC | |
by Mr. Muskrat (Canon) on Jan 19, 2017 at 18:41 UTC | |
| |
by AnomalousMonk (Archbishop) on Jan 19, 2017 at 18:30 UTC |