Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: regex help

by Laurent_R (Canon)
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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1057085]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2018-01-19 15:38 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (221 votes). Check out past polls.