Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: regex help

by Laurent_R (Abbot)
on Oct 05, 2013 at 21:27 UTC ( #1057085=note: print w/ replies, xml ) Need Help??

in reply to regex help

This last solution from jethro is clever and effective, but, with such a problem, I would rather take the solution offered by Corion. I think that, faced with a problem like that, it is often better to think is terms of several simple regexes checking individual conditions, rather than building a single more complicated regex to match all cases. Assuming I have to read and understand some undocumented code, I certainly prefer to have something like:

do_something() if /\d/ and /[A-Za-z]/;

which tells me immediately that I need at least one letter and one digit, rather than:

do_something() if /\d[a-zA-Z]|[a-zA-Z]\d/;

which is quite clear in term of what it does, but less obvious in terms of what the intended underlying rule should really be. Having said that, I also sometimes use these types of supposedly clever shortcuts when they save some typing. But that often implies that I need to add a comment to explain the whole shebang, meaning that I don't save so much typing after all.

Comment on Re: regex help
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2016-05-29 12:10 GMT
Find Nodes?
    Voting Booth?