0

I am using PCRE regex and i would like to capture the string between the tag ?31 and the next ?xx tag but this next ?xx tag could be an optional tag

is there anyway to make the regex to do exactly like what i want?

Thanks

Regex Input Captured group Status
\?31(.*)(?:\?\d{2}) xxx?31testing1?32testing2 testing1 OK
\?31(.*)(?:\?\d{2}) xxx?31testing1 testing2 N/A NOT OK, should be 'testing1 testing2'
\?31(.*)(?:\?\d{2})? xxx?31testing1?32testing2 testing1?32testing2 NOT OK, as ?32 is captured together
\?31(.*)(?:\?\d{2})? xxx?31testing1 testing2 testing1 testing2 OK
\?31(.*?)(?:\?\d{2})? xxx?31testing1?32testing2 N/A NOT OK, should be 'testing1'
\?31(.*?)(?:\?\d{2})? xxx?31testing1 testing2 N/A NOT OK, should be 'testing1 testing2'
smokey
  • 1
  • 1
  • 1
    Try [`\?31((?:(?!\?\d{2}).)*)`](https://regex101.com/r/1a0rLC/1) or [`\?31(.*?)(?=\?\d{2}|$)`](https://regex101.com/r/1a0rLC/2) – Hao Wu Aug 02 '23 at 07:30
  • i think i will use the 2nd option as it is easier to understand to me...thanks again – smokey Aug 03 '23 at 02:28

0 Answers0