http://qs1969.pair.com?node_id=1173589


in reply to Regular expression to check for qwerty sequence in a password

#!/usr/bin/perl -l # http://perlmonks.org/?node_id=1173584 use strict; use warnings; my $password ="asdf"; my $sequences = "qwertyuiop\nasdfghjkl\nzxcvbnm"; if( "$password\0$sequences" =~ /(.{3}).*\0.*\1/s ) { print 'no sequences allowed!'; } else { print "password is okay"; }

Replies are listed 'Best First'.
Re^2: Regular expression to check for qwerty sequence in a password
by bradcathey (Prior) on Oct 09, 2016 at 16:23 UTC

    Interesting. Of course, it works, but I'm not sure what is happening with the:

    "$password\0$sequences"

    and the subsequent:

    \0

    in the regex. I've not see this before and am curious. Thoughts?

    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot

      I use the \0 as a marker or separator between the two sections of the string' Then I match for a three letter sequence that occurs before the marker, some characters, the marker, some characters, and finally the exact three letter sequence that was matched on the left of the marker. If the regex can match, then there is a three letter sequence in the password that matches exactly three keyboard letters in a row.