I need to write a regex to parse a snippet of a swift message field, so I'm using loockbehind.
In the example below I have the two strings that I need from the 12 bic positions.
In the first string 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 to use lookbehind by varying the digits from 3 to 13 because the 3 digits after the "I" or "O" are required. Not resolved because the regex will always find the first 3 digits and will stop.
Pattern = (?<=[IO]\d{3,13})\w{12}
I have tried several conditional approaches without success. Anyone have any suggestions?