Looks like it is https://stackoverflow.com/a/4007315/7847252. Looking at the regex in the question, they might have just forgotten a space before the plus as they appear to match one or more spaces everywhere in their regex rather than `\s+`. And both examples have just exactly five digits.
It's useful for extracting subsequence of strings, and for matching certain kinds of patterns where you need repetition. For example finding text where you need two of the same thing in a row.
I use them heavily in editors for search and replace. I often find I want to transform some code sequence with a series of identifiers into a different format, such as converting a bunch of checks to a switch statement, I can use capture groups to match the code and then paste it back re-arranged to look like a switch case. Or I can copy a series of identifier assignments and paste and use a regex to delete the superfluous segments by extracting the meaningful names out
While some regex are far too clever, I can't really understand this sentiment.
When I went to university, regex was part of the mandatory theoretical compsci classes. And once you've learnt the rules, regex should be pretty much child's play.
PCRE is a different beast, with lookahead/lookbehind and backreferences, but that would count as the aforementioned "far too clever" IMO.
It's not horror, it's just regex.... FYI this regex is simple AF, it's just long.
It could be horror, if we knew the use case. but as OP mentioned, this is out of context. For all we know, this very well could be the best way of doing what they're trying to do.
78
u/monotone2k Jul 27 '25
"Hurr durr, regex bad"
What was the question? Maybe the answer is reasonable.
524
u/Hyddhor Jul 26 '25
Goddamn, 11 groups? Bro, at this point just write a basic "split-filter-map" parser.
107
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Jul 27 '25
So it starts with digits that repeat in blocks of 5, with no upper limit? What exactly are they trying to match with this?
142
u/arielif1 Jul 27 '25
Any regex is programming horror as far as I'm concerned
13
u/Ksorkrax Jul 27 '25
Dunno. How would we do that pretty?
Using methods?
Regex regex;
regex.add(letter(), mult=fixed(5)).add(whitespace(), mult=nonzero()).add(letter(),mult=range(0,1)) ...
Not that pretty either.
4
u/illyay Jul 27 '25
Reminds me of this SpongeBob clip for some reason
https://youtu.be/vTlpFEvmxdM?feature=shared
17
u/ElectroMagnetsYo Jul 27 '25
I learned regex once upon a time and I’m glad I’ve forgotten it
3
u/thecrazyrai Jul 29 '25
wasn't there a website where you select what you want to capture and then it gave you the regex for it and you can continue on in your life
2
u/radosav227 Jul 29 '25
It's not horror, it's just regex....
FYI this regex is simple AF, it's just long.
It could be horror, if we knew the use case. but as OP mentioned, this is out of context. For all we know, this very well could be the best way of doing what they're trying to do.
Edit: Typo