multiple return regex question

V

vorticitywolfe

Hello,

I have a string like such "STAT 09834Z 12004KT VV001 BKN150 OVC220
A3025 T00281039"

I want to grab the VV001 BKN150 and OVC220 part in different variables
$1, $2, $3, etc..

I am parsing the string with this regex:

@return = m/((VV|BKN|OVC)\d{2,4})/g;

and print with

for(@return){print $_,"\n";}

Why does it return:
VV001
VV
BKN150
BKN
OVC250
OVC

?
in the regex I think it's somewhat explicit in keeping the first 2 or
3 characters together and then keeping the rest appended, but perhaps
I'm misinterpreting what it's doing. Any help would be appreciated.

Thank you!
Jonathan
 
P

Peter Makholm

I have a string like such "STAT 09834Z 12004KT VV001 BKN150 OVC220
A3025 T00281039"

I want to grab the VV001 BKN150 and OVC220 part in different variables
$1, $2, $3, etc..

I am parsing the string with this regex:

@return = m/((VV|BKN|OVC)\d{2,4})/g;

You have two capturing parenteses, this means that each time you
pattern matches you get two "results". Use non-capturing parenteses
for the inner group to get what you want:

m/((?:VV|BKN|OVC)\d{2,4})/g;

Read the 'Extended Patterns' part of 'perldoc perlre' for more
information.

//Makholm
 
V

vorticitywolfe

You have two capturing parenteses, this means that each time you
pattern matches you get two "results". Use non-capturing parenteses
for the inner group to get what you want:

m/((?:VV|BKN|OVC)\d{2,4})/g;

Read the 'Extended Patterns' part of 'perldoc perlre' for more
information.

//Makholm

Thanks, worked like a charm!! I knew it had to be something simple! I
haven't quite got all the metacharacters down, but the Extended
Patterns should be of great help! Thanks Again!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top