|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
SitePoint Zealot
![]() ![]() Join Date: Jun 2008
Posts: 183
|
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>
|
|
|
|
|
|
#2 |
|
SitePoint Enthusiast
![]() Join Date: Jun 2007
Location: North Yorkshire, UK
Posts: 36
|
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 |
|
|
|
|
|
#3 |
|
SitePoint Zealot
![]() ![]() Join Date: Jun 2008
Posts: 183
|
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> |
|
|
|
|
|
#4 |
|
SitePoint Enthusiast
![]() Join Date: Jun 2007
Location: North Yorkshire, UK
Posts: 36
|
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 |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 11:38.








Linear Mode
