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.
In reply to Matching a pattern in Regex by rsriram
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |