Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Regex Critic?

by educated_foo (Vicar)
on Nov 18, 2013 at 22:06 UTC ( [id://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.

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-20 16:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found