Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Please help with Regexp::Common

by scorpio17 (Canon)
on Jan 19, 2017 at 15:50 UTC ( [id://1179923]=note: print w/replies, xml ) Need Help??


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

    You might consider adding a test to check if the expected alteration to the original regex was successful. The  \Q(?:\b\E and  \Q\b)\E parts of the substitution are rather fragile IMO and may break if the maintainer(s) of Regexp::Common ever change his/her/their notion of what a proper profane regex should look like.

    c:\@Work\Perl\monks>perl -wMstrict -le "use Regexp::Common; ;; (my $reg = $RE{profanity}) =~ s{\A \Q(?:\b\E (.*) \Q\b)\E \z}{$1}xms or die 'profanity anchor trim failed'; ;; print qq{bad: '$1'} if 'Matsushita' =~ m{ ($reg) }xms; " bad: 'shit'


    Give a man a fish:  <%-{-{-{-<

Re^3: Please help with Regexp::Common
by Mr. Muskrat (Canon) on Jan 19, 2017 at 16:14 UTC

    Shouldn't you be generating passwords that do not contain any words?

      Shouldn't you be generating passwords that do not contain any words?

      https://xkcd.com/936/

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        Fair point but I don't know of that many websites that generate a password longer than 8 characters.

      ... passwords that do not contain any words ...

      Isn't that a bit like the CRM 114 Discriminator strategic communications security system, which for absolute top security was designed not to receive any messages...?


      Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1179923]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-03-29 02:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found