Possilbe to get the index of which alternate matched in a RegExpr?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?QmlsbCBIZXJ0emluZw==?=

    Possilbe to get the index of which alternate matched in a RegExpr?


    I have a regexpr that consist of a set of alternates, e.g:
    (ABC|DEF|XYZ)

    I need to know the index (0,1,2) of the alternate that matched. I can't find
    anything about this (and I've googled it quite a lot!)

    I'm reading a file and creating an indexed collections of objects when my
    programs starts. One of the properties of each object is a match pattern. I
    create the alternation string from these patterns, ansd instantiate a
    RegExpr. The program then gets input from another source, and I pass each
    line of input to the RegExpr. If the RegExpr matches, I need to know the
    index of the alternation that matched, so I can use that to index back into
    the collection and get more information about the object on that line of
    input. Then I can further process that line based on what kind of object it
    is.

    TIA!
    --
    Bill Hertzing
    Tools Development
    ATAPTechnology, Inc.
  • Joachim Van den Bogaert

    #2
    Re: Possilbe to get the index of which alternate matched in aRegExpr?

    Hi Bill,

    What you need is a MatchEvaluator. Here is an example:

    Represents the method that is called each time a regular expression match is found during a Replace method operation.


    Regards,
    Joachim

    Comment

    Working...