0

I have a text documents with a certain number of SIGMETS (aeronautical messages) in a file, for example:

BGGL SIGMET 3 VALID 281815/282215 BGSF-
BGGL SONDRESTROM FIR SEV TURB FCST AT 1815Z WI N7900 W02550 -
N8200 W01150 - N8130 W00805 - N7540 W01815 - N7540 W02440 - N7900
W02550 SFC/FL080 STNR NC=

ENBD SIGMET C01 VALID 281530/281930 ENVV-
ENOR NORWAY FIR OCNL SEV MTW FCST WI N6200 E00530 - N6300 E00830 -
N6300 E01030 - N6200 E01000 - N6200 E00530 SFC/FL260 STNR NC=

ENSV SIGMET B02 VALID 281500/281900 ENVV-
ENOR NORWAY FIR OCNL SEV TURB FCST WI N5900 E00730 - N5900 E00530 -
N6200 E00530 - N6200 E00730 - N5900 E00730 SFC/FL180 STNR NC=

The beginning of a SIGMET is according with this format: /([A-Z]{4}) (AIRMET|SIGMET) (\w{1,3}) VALID (\d{6}\/\d{6}) ([A-Z]{4})-/ and always ends with /(WKN|NC|INTSF)=/.

How can I build a RegEx to match each SIGMET?

Thanks in advance

P.S. I am using JavaScript.

Liuz
  • 17
  • 3
  • Do you want between those or including those opening and closing tags? – Giorgi Nakeuri Apr 11 '16 at 18:13
  • See [this answer](http://stackoverflow.com/a/7504859/3832970). And read the comments below it. There is your answer. There may be a bit cleaner way if your regex engine supports a singleline mode. – Wiktor Stribiżew Apr 11 '16 at 18:27
  • With the kaore answer (Wiktor) the match is from the beginning of the first SIGMET until the last one, I want to separe them. – Liuz Apr 11 '16 at 22:31
  • I would like to include the opening and closing tags. And, I cannot use the Lookbehind tool because I'm using Javascript. – Liuz Apr 11 '16 at 22:32

1 Answers1

0
import re


with open('a.txt') as file:
    data = '\n\n' + file.read() + '\n\n'

pattern = r'\n\n' + r'([A-Z]{4}) (AIRMET|SIGMET) (\w{1,3}) VALID (\d{6}\/\d{6}) ([A-Z]{4})-.*?(WKN|NC|INTSF)=' + r'\n\n'
pattern_compiled = re.compile(pattern, re.DOTALL)

res = pattern_compiled.finditer(data)

if res:
    for i in res:
        print(i)
        print(i.group())
else:
    print('Not found')
Anmol Singh Jaggi
  • 8,376
  • 4
  • 36
  • 77