The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Regex Programming
|
Get recursion number or use result of group in later expression?
Discuss Get recursion number or use result of group in later expression? in the Regex Programming forum on Dev Shed. Get recursion number or use result of group in later expression? Regular expressions forum covering PCRE and POSIX techniques, practices, and standards. Regular expressions help shorten coding time by providing the ability to compact many lines of code into one string.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 15th, 2012, 05:12 AM
|
|
Registered User
|
|
Join Date: Jan 2004
Posts: 16
Time spent in forums: 3 h 7 m 50 sec
Reputation Power: 0
|
|
|
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
or
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.
example:
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, 05:31 AM
|
|
|
|
Hi,
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, 06:42 PM
|
|
Registered User
|
|
Join Date: Jan 2004
Posts: 16
Time spent in forums: 3 h 7 m 50 sec
Reputation Power: 0
|
|
|
Certainty gives answers, uncertainty opinions.
Quote: | Originally Posted by Jacques3 Hi,
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. |
No offense, but that is what the PS was for.
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, 07:22 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
Quote: | Originally Posted by sergiozambrano 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) |
Just because you need it done a certain way doesn't somehow make it possible.
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, 09:21 PM
|
 |
Contributing User
|
|
Join Date: Apr 2012
Location: spaceBAR Central
|
|
Quote: 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
or
to get the current iteration number and match other expressions against |
Post some input examples and what you want the output to be like examples.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|