But then you're just memorizing things like 'start_of_line' instead of '^'. Perhaps easier to read, but no easier to write.
-> start_of_line
-> literal('Flippers')
-> literal(':')
-> optional
-> whitespace_char
-> end
-> remember
-> multiple
-> digit;
I literally can’t parse this as a whole. /^Flippers:\s?(\d+)/ is so much more obvious compared to that utter nonsense.In regex parlance, \d+ explicitly allows for one or more digits. Multiple tacitly implies 2 or more which would be \d{2,}
Also, your end char (which I assume you mean $) would be after the remember -> one_or_more -> digit;
That ‘end’ thing just closes the ‘optional’ group, I believe. There is no $ in an English form of this regex either.
/(\([^()]\|\n\)*\n\([^()]\|\n\)*)
This was from two days ago. I think I was searching a huge sheet of regex match groups for any having line breaks to join. In a month, I'm not even sure I would recognize that I had authored this.I do prefer using parser combinators for more complex tasks.
Sure if they were, we’d already discover them. All of the regex criticism boils down to few simple statements for categories of cases:
1) I didn’t learn regex and have no cheatsheet
Learn it or at least print a cheatsheet and stick it to the wall.
2) The problem that this specific regex solves is a hell of a regular problem under any representation.
Any particular regex is only as terrible as a ladder of corresponding if’s and for’s would be. Deal with it.
3) The problem that this specific regex solves is not a regular language.
Use a proper xml parser.
You have some text to process, open your text editor, you will probably use a dozen regular expressions for that - this is very frequent for many. Can you conceive a better syntax, at least for the simple cases?
In general I would say ~70% of regexes are highly readable. With tools like the above, you can probably go to like ~85%? There are some regexes that are super complicated and then likely should be refactored into a composition of simpler regexes. But that's just a guess. I wonder if there are any studies done about this...
Irregex? http://synthcode.com/scheme/irregex/
They're very effective at what they do as long as you don't make insane brainteasers that make people curse your name.