Angel has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks
I have tried to get this to work, I am trying to extract the pieces from a string that have the pattern [something]. I am trying to write a mail merge program and another mail merge program :) has this syntax
Ideally I thought that the $1....$n held the pieces that the regex found that match. But I am only getting the first match ( since I turned off greedy matching ) and the others are not being found.
Any ideas on what I am missing do I need to copy the string find the match delete it from the string and find again until the regex returns false?
#!/usr/local/bin/perl my $a = "this is a test [[1]] [[ a ]] [[ abd ]] [[\%object,key]]"; $a =~ m/(\[\[.*?\]\])/; print "$_, $1 , $2 , $3 , $4 , $+ \n";
What I would like out is:<\p>
"1, [[1]] , [[ a ]] , [[ abd ]] , [[\%object,key]] , 4 \n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regular Expression Pieces
by dragonchild (Archbishop) on May 07, 2003 at 22:13 UTC | |
by donno20 (Sexton) on May 08, 2003 at 08:25 UTC | |
by dragonchild (Archbishop) on May 08, 2003 at 15:05 UTC | |
|
(jeffa) Re: Regular Expression Pieces
by jeffa (Bishop) on May 07, 2003 at 22:14 UTC | |
by Gilimanjaro (Hermit) on May 08, 2003 at 10:20 UTC | |
|
Re: Regular Expression Pieces
by kelan (Deacon) on May 07, 2003 at 22:21 UTC | |
|
Re: Regular Expression Pieces
by PodMaster (Abbot) on May 07, 2003 at 22:12 UTC |