I have a String like so
2*O#QR 4 F0 P0 A0 J4 C2 D0 I0 Y9 LHRDOH 1505 2345 388 0E
And to get the data I require I have the following regex
^(\d)+[^#$]*[#$](?'code1'\p{Lu}{2})\s*(?'code2'\d{1,4})\b\s*(?<seat1>[A-Z][0-9.](?:\s+[A-Z][0-9.])*+)\s+(?<from>[A-Z]{3})(?<to>[A-Z]{3})\s+(?<other>.*\S)\s*
The problem is that the regex I am using obtains the airline code, seats, from, to and other information. So for the above string it would look something like
1. `2`
code1 `QR`
code2 `4`
seat1 `F0 P0 A0 J4 C2 D0 I0 Y9`
from `LHR`
to `DOH`
other `1505 2345 388 0E`
Sometimes however I get a string like the following which the regex will fail on
3*O#QR 904 J4 C2 D0 I0 Y9 B9 H9 K9 MEL 0055 2125 #1 77W 0E
The difference in the above string is there is no from, only a to (MEL). Is there any way of changing my regex to only look for from and to if they are both present? If not, just look for to?
Thanks