Select the next line after match regex

后端 未结 2 630
我在风中等你
我在风中等你 2020-12-11 06:39

I\'m currently using a scanning software \"Drivve Image\" to extract certain information from each paper. This software enables certain Regex code to be run if needed. It se

相关标签:
2条回答
  • 2020-12-11 07:00

    Did some googling and from what I can grasp, the last parameter to the REGEXP.MATCH is the capture group to use. That means that you could use you own regex, without the \K, and just add a capture group to the number you want to extract.

     \bOrdernr\s+(\S+)
    

    This means that the number ends up in capture group 1 (the whole match is in 0 which I assume you've used).

    The documentation isn't crystal clear, but I guess the syntax is

    REGEXP.MATCH(<ZoneName>, "REGEX", CaptureGroup)
    

    meaning you should use

    REGEXP.MATCH(<ZoneName>, "\bOrdernr\s+(\S+)", 1)
    

    There's a fair amount of guessing here though... ;)

    0 讨论(0)
  • 2020-12-11 07:24

    Description

    ordernr[\r\n]+([^\r\n]+)
    

    Regular expression visualization

    This regular expression will do the following:

    • find the ordernr substring
    • place the line following ordernr capture group 1

    Example

    Live Demo

    https://regex101.com/r/dQ0gR6/1

    Sample text

     1. 21Sid1
     2. Ordernr
     3. E17222
     4. By
     5. Seller
    

    Sample Matches

    [0][0] = Ordernr
     3. E17222
    [0][1] =  3. E17222
    

    Explanation

    NODE                     EXPLANATION
    ----------------------------------------------------------------------
      ordernr                  'ordernr'
    ----------------------------------------------------------------------
      [\r\n]+                  any character of: '\r' (carriage return),
                               '\n' (newline) (1 or more times (matching
                               the most amount possible))
    ----------------------------------------------------------------------
      (                        group and capture to \1:
    ----------------------------------------------------------------------
        [^\r\n]+                 any character except: '\r' (carriage
                                 return), '\n' (newline) (1 or more times
                                 (matching the most amount possible))
    ----------------------------------------------------------------------
      )                        end of \1
    ----------------------------------------------------------------------
    

    Alternativly

    To just capture the line using a look-around so that ordernr is not included in capture group 0 and to accommodate all the variation of \r and \n

    (?<=ordernr\r|ordernr\n|ordernr\r\n)[^\r\n]+
    

    Regular expression visualization

    Live Demo

    https://regex101.com/r/pA4fD4/2

    0 讨论(0)
提交回复
热议问题