CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Regular Expressions:
Complex matching?



Apr 19, 2007, 3:54 PM

Post #1 of 2 (7404 views)
Complex matching? Can't Post

Hi- I'm trying to force a password string to require special characters: must contain at least 1 uppercase letter, 1 lowercase letter, and one non-alphanumeric character. Unfortunately, this must be done using ONLY a one line regular expression--it's for a configuration script that gets read by our Application--so unfortunately, I'm trying to construct a one line regexp that will do this.... I'm not having much luck.

my $pw = 'testThisPw!'; or my $pw = '%testThis!PW'; both of these should pass the regexp test, while: my $pw = 'testingThis' would fail because it doesn't have a non-alphanumeric character...

In any event, I keep confusing myself when trying to attempt to construct a regexp that satisfies all my needs. Is there a "AND" operator in a perl regexp like the "OR" ( | )? Is this even possible to accomplish in a one line regexp? Thanks for the help in advance.


Apr 20, 2007, 9:35 AM

Post #2 of 2 (7391 views)
Re: [ericsemail] Complex matching? [In reply to] Can't Post

Got it:


use strict;
use Test::More qw(no_plan);

my @good = qw(@asdfERER dfdfddf$$$TTTTT TTT$$ddd ddTT$$ Ax?xxxxxxxxxx Ax>);
my @bad = qw(testuser1 asdfasdf@ TERERE%^ asdfasdf ERERERE 23344334 asdfasdfERE\
ERER *&^^%$%$^);

my $re = '^(?:[A-Z].*[a-z].*\W.*|

ok (/$re/ox, "good: $_") for @good;
ok (!/$re/ox, "bad: $_") for @bad;


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives