Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
the 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. -
That 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.
-
Unless this is a log dump processing done using regexs on each of the log lines...
-
Wow, some regexp hater seems to do multi-account downvoting here. I seem to get enough upvotes to keep my answer at zero though...
-
This 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. -
hjk10157313ySome 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.
Related Rants
Oh dear, a scaling problem I solved was replacing some Regex matching with simpler string functions. While I'm a huge fan of Regex, it's unreal how much performance they can suck out of some high-n loops...
I got about 120x out of some critical code thus making a CPU upgrade unnecessary.
rant
wk308
regex
bottleneck
performance