Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Determining uniqueness in a string. (2x)

by tye (Sage)
on Oct 01, 2005 at 06:00 UTC ( [id://496594]=note: print w/replies, xml ) Need Help??


in reply to Determining uniqueness in a string.

The fastest one I found (the only one I tried that was faster than the /(.).*\1/ variations) was certainly not the shortest:

$digits =~ /^(?=.*?0)(?=.*?1)(?=.*?2)(?=.*?3)(?=.*?4)(?=.*?5)(?=.*?6)( +?=.*?7)(?=.*?8)(?=.*?9)/;

But it was about twice as fast.

Update: Added the '^' to make failure cases fast.

The (?=.*?0) asserts that $digits contains a '0'. If that fails, then the regex fails. If a '0' is found, then (since that was a look-ahead assertion), we start over at the beginning of $digits and (?=.*?1) asserts that $digits contains a '1'. etc.

- tye        

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-03-28 08:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found