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

Re: Regex Critic?

by LanX (Canon)
on Nov 18, 2013 at 21:30 UTC ( #1063204=note: print w/ replies, xml ) Need Help??


in reply to Regex Critic?

Not that easy.

There are different categories of "bad practice" like unmaintainable code or dangerous code.

It's possible to built little regexes which run for years just b/c backtracking goes exponential in Perl but not in egrep.

So this depends on the engine used and involved optimization. (that much about "static analyzer for several languages")

At the same time the code you showed m/^.*blah.*$/ might be odd but not necessarily slower, cause AFAIK will Perl first try to find the string "blah" somewhere, before continuing.

And it's NOT IDENTICAL to m/blah/ cause multilines wouldn't match w/o /s modifier.

DB<100> $str="\n blah \n" blah DB<101> $str =~ /blah/ => 1 DB<102> $str =~ /^.*blah.*$/ DB<103> $str =~ /^.*blah.*$/s => 1

So what's the recommended best practice here in your opinion?

Regarding analyzers, you might be interested in this recent discussion, which had pointers to different projects and older discussions:

Parsing and translating Perl Regexes

HTH! =)

Cheers Rolf

( addicted to the Perl Programming Language)


Comment on Re: Regex Critic?
Select or Download Code
Re^2: Regex Critic?
by QM (Vicar) on Nov 19, 2013 at 11:16 UTC
    Thanks for the pointers. I've read somewhere else, for instance, a recommendation to always use /ms unless there's a good reason not to. Also educated_foo's suggestion below for /a and /aa.

    Ultimately I'd like to collect a reasonable list for Perl REs, and where necessary, extend/amend that for non-Perl.

    -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://1063204]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2014-12-18 02:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (41 votes), past polls