Saturday, 15 June 2013

regex - Regular expression grouping matching validation -


I want to know if someone certifies whether a group has prepared a match or not. For example, let's see what I want to do with the following 2 strings:

  String 1: "Start testing another type of magic" String 2: "test xyz end "Start   

I want to get the string containing the keyword magic and test (both) but there are some issues:

  • Magic and test can not be continuous with each other. For example, magic word 1 test word2 end
  • magic and test can not be in the string in that order , I.e., a match must be given for magic test and start and test magic and .

    To handle it, after the regular expression:

      start ((w1) * (w2) * \ [^ (end)]) + End   

    ... which means:

    • should start with the string start and end < End with / code>. Use w1 and w2 in any order and use other words which are not end thanks [<{/ code> .
    • Later, match ends.

      The problem with that regular expression is that [^ (end)] and w1 and w2 in the actual string I need to discard the words between .

      To match the regular expression string 1, it will:

        start (magic) * (test) * [^ (end)) + end   

      ... that only needs 1 string match (and this is what I want). But the string 2 also matches

      Is there any kind of investigation that the group has been matched with the Reggax engine? Something went like magic and test to check keywords (if \ 1! = Null) ? I have to do it with regexes because I can not work with it in the source code, its purpose is to work with command line use.

      description

      This expression will be:

      • end
      • Code> magic and test must be in any order
      • the word magic and test

        ^ start (? = \ S) (? =. * \ Smagic (? = \ S)) (? =. \ * \ Stest (? = \ S)). * \ Send (\ r | \ n | \ z)

        Image Details Enter here

        Input Text

          Introducing Magic: Another term begins at the end of the trial, And will start a magic show with Tony Wonder who will end up examining   

        ** Output

          [0] = & gt; Another type of magic test begins: [1] = & gt; Start a magic show with Gob and Tony Wonder, which will end up examining    

No comments:

Post a Comment