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

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.
  • ...


Comment on Re: Regex Critic?
Re^2: Regex Critic?
by QM (Vicar) 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.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (14)
As of 2014-07-29 12:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (217 votes), past polls