Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Regex Critic?

by educated_foo (Vicar)
on Nov 18, 2013 at 22:06 UTC ( #1063208=note: print w/replies, xml ) Need Help??

in reply to Regex Critic?

PBP probably has some tips, but other than that, I can't think of anything off the top of my head, neither a program nor a list. To start one...
  • ".*" is greedy, which will probably do something you don't expect in the future, so think about how you're using it.
  • be careful with "^" and "$" when not doing line-oriented string processing. But don't sweat it -- most of the time you are, so they do the right thing.
  • be explicit when you might have to touch Unicode, e.g. "\d" matches all kinds of junk that the rest of Perl doesn't think is a digit. IMHO, all regexes should have the new "/aa" modifier on them, unless you know the reason they shouldn't.
  • ...

Replies are listed 'Best First'.
Re^2: Regex Critic?
by QM (Parson) on Nov 19, 2013 at 11:20 UTC
    Thanks for the comments. .* always sets off the alarm in my head, as it is very rarely necessary. Similarly, constructs like m/^.*blah.*$/ are overkill in many cases, and make it harder to see what's doing the real work.

    I've had a look at the /aa modifiers, and I think that might make our list. And the use re '/aa' pragma might be the best way to do that for our code.

    Quantum Mechanics: The dreams stuff is made of

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1063208]
and the fog begins to lift...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2018-05-24 18:42 GMT
Find Nodes?
    Voting Booth?