Birgit Kellner wrote: > > I would like to replace all double with single quotes inside a html tag, > i.e. perform the substitution only for html tag attributes, but not outside > tag boundaries. > > my $string = qq|<a href="http://someurl.url" title="welrkwlekrj">aha</a>, > and here "follows" a > quoted expression: "blabla"<img src="http://someimage.gif" width="80" > height="200">|; > > All double quotes should be replaced by single ones except those > surrounding the string "blabla". > > My approach would be: > Look for <, followed by a string of characters except >, followed by" - if > matched, replace this instance of " with '. > > I found the following code to work, but it strikes me as very clumsy and I > am not sure whether it captures all relevant cases and really excludes all > those which are not relevant. > > while ($string =~ /(<[^>]*?)"/gs) { > my $var = $1; > $string =~ s/$var"/$var'/;} > > print qq|$string\n|;
$string =~ s/(<[^>]+>)/$a=$1;$a=~tr|"|'|;$a/eg; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]