John,

can you explain the piece of code that you wrote.

Thanks and happy new year  :-)
----- Original Message -----
From: "John W. Krahn" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, December 30, 2001 3:38 AM
Subject: Re: regexp to replace double with single quotes inside html tags


> 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]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to