3
I need to write a regex to parse an excerpt from a field of the Swift message, so I’m using loockbehind.
In the example below I have the two strings I need from the 12 positions of Bic.
In the first string it would be TESTBIC34XXX
In the second string YOURBANKXJKL
The problem is that the fields between O564
and TESTBIC34XXX
are optional
String1 = "2:O5641057130214TESTBIC34XXX26264938281302141757N"
String2 = "2:I101YOURBANKXJKLU3003"
I tried using lookbehind by varying the digits from 3 to 13, because the 3 digits after "I" or "O" are required. It didn’t because regex will always find the first 3 digits and will stop.
Pattern = (?<=[IO]\d{3,13})\w{12}
I’ve tried several unsuccessful conditional approaches. Does anyone have any suggestions ?
Guilherme, thanks for the full answer, helped a lot to clarify the concept of the lookbehind, very good reference, I ended up marking Wtrmute’s response because he answered before. But anyway thanks for the help.
– WPSC
@user1987610 Quiet, good that helped :D
– Guilherme Lautert