0

I tried to capture the second match from given text i.e,

hash=e1467eb30743fb0a180ed141a26c58f7&token=a62ef9cf-2b4e-4a99-9335-267b6224b991:IO:OPCA:117804471:OPI:false:en:opsdr:117804471&providerId=paytm

In the above text, I want to capture the second number with the length of 9 (117804471).

I tried following, but it didn't work; so please help me resolving in this.

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

Ram Kowsu
  • 711
  • 2
  • 10
  • 30

1 Answers1

0

You can use

^(?:.*?\K\b[0-9]{9}\b){2}

See the regex demo.

Details:

  • ^ - start of string
  • (?: - start of a non-capturing group:
    • .*? - any zero or more chars other than line break chars (as few as possible) followed with
    • \K - match reset operator discarding text matched so far
    • \b[0-9]{9}\b - a 9-digit number as a whole word
  • ){2} - two occurrences of the pattern sequence defined above.
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563