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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace all instances but one

Status
Not open for further replies.

mpalmer12345

Programmer
Feb 16, 2004
59
US
Here's a question I have been puzzling over for a while.

I want to replace all pretags in a text with "", EXCEPT the   pretag.

I figure that $text =~ s/&[a-zA-Z]+?;//ig; will wipe out ALL of them. But how do I wipe out all but  ?

I've tried a few dumb things, but I can't seem to make it work, so I appeal to the higher forces here.
 
This seems to work:
Code:
$text =~ s/(&[a-zA-Z]+?;)/lc($1) eq " "? $1: ""/eig;
Or, less cryptically:
Code:
while ($text =~ /(&[a-zA-Z]+?;)/ig) {
    if (lc($1) ne " ") {
        $text =~ s/$1//;
    }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top