Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple APILearn More
tosensei3899297dthe key to using regex:
* as much as needed.
* as little as possible.
* and then a bit less.
and document _precisely_ what and how a regex (of any non-trivial complexity) is doing. even near-future-you will thank you.
Oktokolo10156297dThat must have been either: A really bad regexp, a really bad algorithm leading to multiple use of the regexp on the same data, or just a heeeeeeeeap of data.
magicMirror10324297dUnless this is a log dump processing done using regexs on each of the log lines...
Paps28297dI like this kind of rant because it makes me discover things I didn't know.
Oktokolo10156296dWow, some regexp hater seems to do multi-account downvoting here. I seem to get enough upvotes to keep my answer at zero though...
EmberQuill3885292dThis reminds me of the time I tried to validate IPv4 CIDR ranges with regex. The pattern ended up becoming stupidly complicated until I decided to forego regex entirely. I ended up splitting the string and parsing the octets into numbers, then validated with simple math.
Regex has its place but sometimes it just isn't the best option.
hjk1015137291dSome things are not suited for regex. It's often used as a hammer while it can be a scalpel.
Also the implementations vary. When you do a loop like that at least use an implementation that can compile the regex and use that.