RegEx: Tag matching

Viewed 45

So I have this tag:

^27=10^**370=B10,11**^ 312=7,12,-10,1000 ^368=5,5,10 ^375=B12,2^26=8.0000 ^369=1.0000^5=8.0000^6=9.0000^14=1^15=1^263=1^MVAL=100^NOIA=1

I'm trying to match the 11 of the 370=B10,11.

I currently have this:

(?<=\^370=B\d\d,)[\d]+

which works for this case but the number following the B can be 1 or 2 digits and this:

(?<=\^370=B\d+,)[\d]+

doesn't work because lookbehind requires a fixed width.

Any idea how I can make this robust to work for different combinations: 370=B1,11 and 370=B10,11

1 Answers

You can use a PCRE/Boost/Ongigmo compliant regex like

\^370=B\d+,\K\d+

See the regex demo. Details:

  • \^370=B - ^370=B text
  • \d+ - one or more digits
  • , - a comma
  • \K - match reset operator that discards the text matched so far from the overall match memory buffer
  • \d+ - one or more digits.
Related