Is there a compelling reason to use quantifiers in Perl regular expressions instead of just repeatin

Posted by Morinar on Stack Overflow See other posts from Stack Overflow or by Morinar
Published on 2010-03-30T18:23:39Z Indexed on 2010/03/30 18:33 UTC
Read the original article Hit count: 378

Filed under:
|
|

I was performing a code review for a colleague and he had a regular expression that looked like this:

if ($value =~ /^\d\d\d\d$/) {
    #do stuff
}

I told him he should change it to:

if ($value =~ /^\d{4}$/) {
    #do stuff
}

To which he replied that he preferred the first for readability (I find the second more readable, but that's a religious debate I'll save for another day).

My question: is there an actual benefit to one over the other?

© Stack Overflow or respective owner

Related posts about perl

Related posts about regex