rsriram has asked for the wisdom of the Perl Monks concerning the following question:
Hi, In my markup file, I want to check for a occurrence which matches, <figr n="(.+?)">(.*?)<\/figr> and replace it with the below mentioned tag.
if($_ =~ /<figr n="(.+?)">(.*?)<\/figr>/)
{
$fno=$1;
$figno=sprintf("%03d", $fno);
$_ =~ s/<figr n="(.+?)">(.*?)<\/figr>/<FIGIND NUM="$fno" ID="FG.$figno">$2<\/FIGIND>/g;
}
The original value of figr in the markup file should be filled with preceeding zero's to make it a 3 digit number. My problem is, if I have two <figr n="#"> elements in a same line, the value of the first indicator is getting used for the second indicator too.
For example,
Nerve cells come in many shapes and sizes, but they all have a number of identifiable parts. A typical nerve cell is shown in <figr n="1">Figure 1</figr>. Like all other cells in the body, it has a nucleus that contains genetic information.<figr n="2">Figure 2</figr>. The cell is covered by a membrane and is filled with a fluid.
The output is created as:
Nerve cells come in many shapes and sizes, but they all have a number of identifiable parts. A typical nerve cell is shown in <FIGIND NUM="1" ID="FG.001">Figure 1</FIGIND>. Like all other cells in the body, it has a nucleus that contains genetic information.<FIGIND NUM="1" ID="FG.001">Figure 2</FIGIND>. The cell is covered by a membrane and is filled with a fluid.
Can anyone tell me what's wrong in my code? I also tried using <figr n="([^"]+)"> in search instead of the above pattern.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Matching a pattern in Regex
by davorg (Chancellor) on Jul 25, 2006 at 10:22 UTC | |
by Ieronim (Friar) on Jul 25, 2006 at 10:40 UTC | |
by davorg (Chancellor) on Jul 25, 2006 at 10:45 UTC | |
|
Re: Matching a pattern in Regex
by Hofmator (Curate) on Jul 25, 2006 at 10:35 UTC | |
|
Re: Matching a pattern in Regex
by GrandFather (Saint) on Jul 25, 2006 at 10:36 UTC | |
by Ieronim (Friar) on Jul 25, 2006 at 12:02 UTC | |
|
Re: Matching a pattern in Regex
by rodion (Chaplain) on Jul 25, 2006 at 10:57 UTC | |
|
Re: Matching a pattern in Regex
by Ieronim (Friar) on Jul 25, 2006 at 10:28 UTC | |
|
Re: Matching a pattern in Regex
by davidrw (Prior) on Jul 25, 2006 at 12:23 UTC |