Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regex to replace SSI syntax in HTML

Status
Not open for further replies.

fyyap

Programmer
Oct 29, 2001
9
SG
Hi,

Could anybody guide me how to write a regex to replace SSI syntax in HTML??

Replace all SSI occurences in a HTML page, i.e.

<!--#include file="/include/common/header.html" -->
<!--#include file="/include/common/disclaimer.html" -->
<!--#include file="/include/common/footer.html" -->

with :-

<!--#include file="include\common\header.html" -->
<!--#include file="include\common\disclaimer.html" -->
<!--#include file="include\common\footer.html" -->


Appreciate your prompt help! Thanks so much!


 
Easy, the following makes that exact translation:

Code:
$html = q{
<!--#include file="/include/common/header.html" -->
<!--#include file="/include/common/disclaimer.html" -->
<!--#include file="/include/common/footer.html" -->};

[COLOR=blue]$html =~ s{(?<=<!--#include file=")/([^"]*)(?=" -->)}{join '\\', split '/', $1}eg;[/color]

print $html;

Output:
Code:
<!--#include file="include\common\header.html" -->
<!--#include file="include\common\disclaimer.html" -->
<!--#include file="include\common\footer.html" -->
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top