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

Dear Monks, I thought I would know how to do this, but I must be having a senior moment. I want the prevent users from entering passwords with repeating characters, well 2 repeating characters is ok but 3 or more is right out. I thought that ...
next if $pass =~ m/.{3,}+/g;
... would but that matchs non-repeating characters too. I sure that there is an easy way to do this.

Thanks!

Replies are listed 'Best First'.
Re: How to match repeating characters
by JavaFan (Canon) on Apr 09, 2010 at 22:39 UTC
    next if $pass =~ /(.)\1{2}/;
    No addition + or trailing /g. That would do things in triplicate.

      That would things in triplicate.

      While if //g is quite bad — it can lead to weird errors down the line — it doesn't triplicate anything.

Re: How to match repeating characters
by graff (Chancellor) on Apr 10, 2010 at 04:45 UTC
Re: How to match repeating characters
by BrowserUk (Patriarch) on Apr 10, 2010 at 00:44 UTC

    It's not clear if you mean consecutive repeating or more than 2 repeats anywhere. If the latter, this might work:

    c:\test>p1 { printf "password: "; chomp( my $pass = <STDIN> ); redo if $pass =~ m[(.).*\1.*\1]; print "'$pass' Ok"; redo };; password: hello 'hello' Ok password: goodbye 'goodbye' Ok password: xxx password: xaxbxc password:

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.