SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: search for last tag in a file
-
Nov 5, 2009, 06:17 #1
- Join Date
- Jun 2008
- Posts
- 205
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
search for last tag in a file
How to set a flag and search for the last <p> tag in a file and substitute with <con>
-
Nov 5, 2009, 11:01 #2
- Join Date
- Jun 2007
- Location
- North Yorkshire, UK
- Posts
- 483
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
If you are using perl and the contents of your file are in the variable $a then you can use the regular expression.
$a =~ s/^(.*)<p>(.*?)$/$1<con>$2/s
-
Nov 5, 2009, 12:12 #3
- Join Date
- Jun 2008
- Posts
- 205
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
if input is as below
Code:__DATA__ <id>000044119</id>> <DD>Friday, October 30, 2009</DD>> <p>THis is param1</p> <p>THis is param2</p> <p>THis is param3</p> </root>
Code:__DATA__ <id>000044119</id>> <DD>Friday, October 30, 2009</DD>> <con><p>THis is param1</p>> <p>THis is param2</p>> <p>THis is param3</p></con> </root>
-
Nov 5, 2009, 13:07 #4
- Join Date
- Jun 2007
- Location
- North Yorkshire, UK
- Posts
- 483
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You seem to be changing </p> to </p>> except for the last </p> and putting a <con> before the first <p> and a </con> after the last </p>.
I would do two substitutes.
$a =~ s/<\/p>/<\/p>>/sg
$a =~ s/^(.*?)(<p>.*<\/p>)>(.*?)$/$1<con>$2<\/con>$3/s
If the </p> to </p>> was not intended then just
$a =~ s/^(.*?)(<p>.*<\/p>)(.*?)$/$1<con>$2<\/con>$3/s
Bookmarks