October 15th, 2012, 06:12 AM
Get recursion number or use result of group in later expression?
I need to match consecutive numbers, and repeat the same piece of regex as long as they keep incrementing, and what would really reduce my expression, 250+ characters long already! (or rather make it more elegant) would be to:
be able to use the result from one capture group in another expression later
to get the current iteration number and match other expressions against
PS: It HAS to be regex expression and replacement ONLY. A second search/replace pass is acceptable though.
text 1 matches
text 2 matches
text 3 matches
text 6 doesn't match. end.
text 1 shouldn't even get here (or start over?)
- I heard about using backreferences in the same expression, as a conditional, and I heard about Recursions and matching the level number…, but that's still too far from my knowledge of regex to combine them.
October 15th, 2012, 06:31 AM
Wow. I've seen regexes misused a lot for all kinds of things (like parsing XML), but this one takes it to a new level.
No offense, but regexes are not made for doing math. Simply search for numbers and leave it to your application to check if they're consecutive.
October 17th, 2012, 07:42 PM
Certainty gives answers, uncertainty opinions.
No offense, but that is what the PS was for.
Originally Posted by Jacques3
Regardless of "being possible" with other methods, it NEEDS to be done in this way (through an existing plugin that performs regex search/replace from wordpress admin panel)
Any trick yo could imagine will be welcome along with your advice/opinion. A single "It's not possible" or "I don't know" is preferred, because even knowing it's DEFINITELY not possible is more useful than just questioning my application.
So… I'll asume you are not confident (nor have explored enough) to know with certainty that at least "it's not possible", and I'll add ( to prevent others to believe I've been taken care of): Anyone?
October 17th, 2012, 08:22 PM
Just because you need it done a certain way doesn't somehow make it possible.
Originally Posted by sergiozambrano
Unless you can write some code of some kind somewhere, regular expressions cannot do this. You'd have to pare down the problem quite a bit before this would be possible, and even then the closest thing I can think of is so ridiculously complex (writing an HTML parser would be a walk in the park, comparatively) that I'd say it's not humanly possible.
October 17th, 2012, 10:21 PM
Post some input examples and what you want the output to be like examples.