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

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1057085]
[karlgoethebier]: Good morning
[Discipulus]: good morning vietnam!
[Discipulus]: but there is some perl workshop somewhere? I notice many high level monks disappeared.. we can make PM a squat in the meantime ;=)
[karlgoethebier]: Discipulus: Mmh, who disappeared?
[marto]: morning all
[shmem]: perl -lE '$_="odd mornin";($o=$_)=~ s/^|$/g/g;say$o'

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2017-06-27 08:05 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (600 votes). Check out past polls.