Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Removing similar characters

by rspishock (Monk)
on Sep 01, 2011 at 22:41 UTC ( [id://923733]=note: print w/replies, xml ) Need Help??


in reply to Re: Removing similar characters
in thread Removing similar characters

Thanks for the tip. I was guessing that using a regex was probably going to be one of the best ways to achieve this. Since I'm not too familiar with using regex, my question is can I direct the regex to the array which contains the characters? For example, since I want to be able to check 88 individual characters for duplicates.

Below is a small portion of the script that I'm working on.

my @chars6 = ('0'..'9', 'a'..'z', 'A'..'Z', '!','@', '#', '$', '%', '^', '&', '*', '(', ')', '<', '>', '?', '`', '+', '/', '[', '{', ']', '}', '|', '=', '_','~', ',', '.'); if ($level == 5) { m/@chars6/ #generate new password }

Looks like I'm off to Amazon to get a book to start learning regex.

Replies are listed 'Best First'.
Re^3: Removing similar characters
by Kc12349 (Monk) on Sep 02, 2011 at 12:47 UTC

    A better bet is to generate a string from that array and insert it into the regex pattern. I did this below with the string $chars6_class. Note that I escaped many of the symbols which have special meaning in regex and perl, though I didn't really double check I got all the right ones.

    Then I use the back reference, \1, to look for two more occurrences of what I just found.

    my @chars6 = ('0'..'9', 'a'..'z', 'A'..'Z', '!','\@', '#', '\$', '\%','^', '&', '\*', '\(', '\)', '<', '>', '\?', '`', '\+', '\/', '\[', '\{', '\]','\}', '\|', '=','_', '~', ',', '\.'); my $chars6_class = '[' . join( '', @chars6) . ']'; if ($password=~ m/($chars6_class)\1{2}/) { # regenerate password }

    Further, I would take a look at the posix character classes to see if there is already a set of what you are looking for. My guess would be that you could just use the below regex instead of dealing with an array of characters.

    m/([[:alnum:]]|[[:punct:]])\1{2}/

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-03-29 06:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found