I am working with some data that the last portion of sometimes has additional information than others. When this additional information exists, I need regex to skip it and move on to the next line.
So sometimes my data ends like this: LAT:35.7427280 LONG:-86.1315921 GRIDREF:01800S 01600E
Other times it ends like this: LAT:35.7427280 LONG:-86.1315921
(There is a lot more before that, but I have removed it for simplicity)
In the below code, sometimes “GRIDREF” exists and I just need it to ignore that and move on to the next line. Sometimes it does not exist, in which case I need it to move on to the next line. Either way, after LONG ends, I just need it to move on to the next line and ignore everything after LONG.
sLAT:(?<lat>.*?)sLONG:(?<long>.*?)s*(?:GRIDREF:.*?s*)
Currently if GRIDREF does not exist, then it makes “long” the entire next line, until it comes to “GRIDREF”. I have tried removing “GRIDREF” – but so far, that causes that data (if it exists) to be included in “long”
I have tried sLAT:(?<lat>.*?)sLONG:(?<long>S*?)
hoping that would just ignore anything once it comes to the space after LONG:, but it gets stuck with that.