#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    16
    Rep 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.
  2. #2
  3. No Profile Picture
    Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    57
    Rep Power
    0
    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.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    16
    Rep Power
    0

    Certainty gives answers, uncertainty opinions.


    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?
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,055
    Rep Power
    9398
    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.
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    spaceBAR Central
    Posts
    229
    Rep Power
    42
    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.

IMN logo majestic logo threadwatch logo seochat tools logo