dslreports logo
 
    All Forums Hot Topics Gallery
spc
uniqs
16
dave
Premium Member
join:2000-05-04
not in ohio

dave to Drunkula

Premium Member

to Drunkula

Re: REGEX HOWTO's/Tutorials for BASH scripts/commands

said by Drunkula:

I'm no regex master but just a suggestion... Wouldn't it be better to replace the [0-9][0-9] with [\d]{2} instead?

Better in what sense? Unless this is destined for a long life where it will be examined and modified by others, I think the rule of 'whatever works' applies here.

Besides (1), [0-9][0-9] is probably valid in practically any regular-expression parser anywhere, and [\d]{2} is much less universal.

Besides (2), [0-9][0-9] is certainly more obvious to the reader (which is why our writer came up with this form).

Don't sweat the small stuff.
pablo
MVM
join:2003-06-23

pablo

MVM

I think the rule of "what's more obvious to the maintainer" (paraphrasing what you wrote should trump "whatever works"

Of course, if we're talking super critical, kernel code, then tune the hell out of it and document 2x more.

Cheers,
-pablo
dave
Premium Member
join:2000-05-04
not in ohio

dave

Premium Member

Personally, I'm in favour of "the entire filter program needs to be expressed in one single pattern-match and in the shortest possible regexp", but I don't think that sort of attitude will help the OP
pablo
MVM
join:2003-06-23

pablo

MVM

Are you suggesting a nerd-a-thon where we try to take his expression and crunch it to the smallest possible RE? hah hah!

Just kidding!

-pablo