Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Regex Critic?

by LanX (Bishop)
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)

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.

    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://1063204]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2017-12-17 03:37 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (462 votes). Check out past polls.