dcsimg
Results 1 to 9 of 9

Thread: RegEx for if previous match equals

  1. #1

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,325

    RegEx for if previous match equals

    I have seen this before but forgot how to do it...

    Basically I want to match a named group called opening... then if the match = a pattern then do a specific thing... eg:

    (?<Opening>{|<|\().*?
    .... Then stuff after this to go if Opening={ then match } ElseIf Opening=< then match > ElseIf Opening=\( then match \)

    Thanks,
    Kris

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    22,125

    Re: RegEx for if previous match equals


  3. #3

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,325

    Re: RegEx for if previous match equals

    Quote Originally Posted by .paul. View Post
    This is not what I want I know how to do those.

  4. #4

  5. #5

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,325

    Re: RegEx for if previous match equals

    I also no about how to check if a match exists and have a condition on that ... but what I really want is a way to re-check if the previous match also matches something else to determine the criteria ..
    (I know I could have multiple conditions ... but would be nicer if I didn't have to).

    Thanks,
    Kris

  6. #6

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,325

    Re: RegEx for if previous match equals

    I thought there was a way to do this ...
    Basically with the check to see if it exists I would have to go:

    ((?<Opening1>\{)|(?<Opening2>\<)|(?<Opening3>\()).*?(?(Opening1)\}|(?(Opening2)\>|(?(Opening3)\)|)))

    ... would be nicer to do something like:

    (This is not valid just a mock up of the kind of thing that I want to do
    (?<Opening>\{|<|\().*?((?(Opening=\{)\})|(?(Opening=\<)\>)|(?(Opening=\()\)))

    Kris
    Last edited by i00; Apr 17th, 2019 at 11:16 PM. Reason: Fixed bug in regex

  7. #7
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,766

    Re: RegEx for if previous match equals

    why dont you supply a sample text with the expected output
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  8. #8

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,325

    Re: RegEx for if previous match equals

    This is a just a sample ... i think the opening post is self explanatory.. the eg is to match each type of bracket ({< up to their closing bracket )}>

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    22,125

    Re: RegEx for if previous match equals

    To refer to a previous match, you can use $[index] i.e. $1 or something similar. I'm not sure how you'll implement that with conditionals...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width