Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Regex, how to pull out multiple matches per line into array?

by choroba (Cardinal)
on Aug 04, 2015 at 17:24 UTC ( [id://1137404]=note: print w/replies, xml ) Need Help??


in reply to Regex, how to pull out multiple matches per line into array?

The matching in list context returns the matching groups ($1, $2...), which are created by parentheses in the regular expression. You should add another pair of them that spans the whole macro, you should also turn the inner group into a non-matching one so it doesn't pollute the results:
#!/usr/bin/perl use warnings; use strict; my @inarr = ( 'stuff{tag}<igo;123>stuff<ig;abc>', '<igt;ddd>stuff blah {foo}', 'stuff blah foo <igxo;dsldkd.eps>', '<igt;aaa>stuff blah <igx;hhh>', ); my $re = qr/( < (?: ig | igt | igo | igxo ) ; .+? > )/x; for my $lin (@inarr) { my @g = $lin =~ m/$re/g; print join ' ', map "[$_]", @g; print "\n"; }
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1137404]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-03-28 21:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found