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?