in reply to Re: Please help with Regexp::Common
in thread Please help with Regexp::Common
I followed your suggestion and tried this:
use strict; use Regexp::Common; (my $reg = $RE{profanity}) =~ s{\A \Q(?:\b\E (.*) \Q\b)\E \z}{$1}xms; while ( my $word = <DATA> ) { chomp $word; if ( $word =~ m/$reg/ ) { print "Profanity detected: \"$word\"\n"; } else { print "$word\n"; } } __DATA__ aaaabbbbcccc aaaashitcccc aaaa1234cccc ddddeeeeffff
This way it will find embedded "bad words" without the need for spaces around them, which is what I wanted. I realize the logic in requiring the word boundaries. But I think the fact that $RE{num}{int} finds embedded numbers made me assume that $RE{profanity} should work the same way, or else there might be a switch to toggle the behavior one way or the other.
The reason I need this is to generate temporary (one-use) passwords (like when someone requests a password reset on a website). The generated password should, ideally, be a jumble of random letters and/or numbers, but I don't want to accidentally send someone a password with an "obvious" obscenity embedded, so a simple filter like this is helpful.
Thanks!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Please help with Regexp::Common
by AnomalousMonk (Archbishop) on Jan 19, 2017 at 18:11 UTC | |
Re^3: Please help with Regexp::Common
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 Your Mother (Archbishop) on Jan 19, 2017 at 19:14 UTC | |
by AnomalousMonk (Archbishop) on Jan 19, 2017 at 18:30 UTC |