You may need nested grouping toward the content based on the end of the spec, but at least the early part of a METAR should give you no concern.
The following approach embodies the advice (brilliant minds come to similar solutions?) re breaking the METAR or SPECI down into tokens:
($metar is taken straight from the ref doc, with digits substituted for YYGGgg and with the ticks escaped, as comprehensively understanding the spec would require more time than I have to give, just now.)#!/usr/bin/perl -lw use strict; my $metar = 'METAR CCCC 210855Z AUTO dddff(f)Gfmfm(fm)KTv dndndnVdxdxd +x VVVVVSM [RDRDR/VRVRVRVRFT ] w\'w\' [NsNsNshshshs or VVhshshs T\'T\' +/T\'dT\'d APHPHPHPH'; if ( $metar =~ /^(METAR|SPECI)\s([A-Z]{4})\s(\d\d)(\d{4}Z)\s(AUTO|COR) +.*/) { my $type= $1; my $stn= $2; my $monthday = $3; my $obsTime= $4; my +$subtype= $5; print $type . " Station: $stn, Date: $monthday, ObservationTime: $ +obsTime, Subtype: $subtype"; } else { print "ww screwed up the regex."; }
In reply to Re: Speeding up a large regex match pattern
by ww
in thread Speeding up a large regex match pattern
by wossname
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |