Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Regex Critic?

by LanX (Saint)
on Nov 18, 2013 at 21:30 UTC ( [id://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)

Replies are listed 'Best First'.
Re^2: Regex Critic?
by QM (Parson) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1063204]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2024-04-18 13:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found