0

I'm currently parsing some data which is separated by patterns like "?31" or "?32". There is one Field with an IBAN and the next one holds the name. A sample would be :

?31DE16170619340006562160?32Jan Doufe

The regex I use is (Sample):

\?31(.{0,34})?(?=\?[0-9]{2}|$)

The resulting match is:

DE16170619340006562160?32Jan Doufe

This result is 34 characters long, which would be the maximum length of the desired value. If the name was one character longer only this would match:

DE16170619340006562160

That is the result I want to have. To me it seems like the positive lookahead ((?=\?[0-9]{2}|$)) in the regex does not match the first occurrence but the last one. How would I have to change it, so that the lookahead matches the first occurrence?

Romano Zumbé
  • 7,893
  • 4
  • 33
  • 55
  • 4
    Use a lazy version of the limiting quantifier: `(.{0,34}?)` – Wiktor Stribiżew Aug 03 '17 at 13:23
  • @WiktorStribiżew Thanks a lot. I'm not really sure, what the replacement of the `?` really means for the regex. I thought this would be the same. It seems I underestimated the mystics of regexes – Romano Zumbé Aug 03 '17 at 13:26

0 Answers0