bulrush has asked for the wisdom of the Perl Monks concerning the following question:
I need to find all matches to a regex and put each match from a single scalar, into one or more positions in an array. I'm trying to pull out strings that look like /<(ig|igt|igo|igxo);.+?>/. Basically I need to pull out macros that begin with "<ig;", "<igt;", "<igo;", "<igxo;" and end with ">". This is my attempt.
After this runs on $inarr[0], @g should contain:my($re,$lin,@g,@inarr); 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>' ); $re='<(ig|igt|igo|igxo);.+?>'; foreach $lin (@inarr) { @g=($lin=~m/$re/g); } # foreach
but I'm getting:@g=('<igo;123>', '<ig;abc>' );
What am I doing wrong here? I've already searched Google but haven't found what I'm looking for yet.@g=('ig');
Thank you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex, how to pull out multiple matches per line into array?
by toolic (Bishop) on Aug 04, 2015 at 17:23 UTC | |
by bulrush (Scribe) on Aug 04, 2015 at 17:45 UTC | |
|
Re: Regex, how to pull out multiple matches per line into array?
by choroba (Cardinal) on Aug 04, 2015 at 17:24 UTC | |
|
Re: Regex, how to pull out multiple matches per line into array?
by GrandFather (Saint) on Aug 04, 2015 at 20:59 UTC |