John W. Krahn wrote:
>
> Rodney Wise wrote:
>
> >
> > I'm trying to place HTML Tags around the contents of Quoted material.
> >
> > I'm using the following PERL code:
> > $TextBlockToConvert =~ s/"(.+?)"/"<FONT Color=BLUE>\1<\/Font>"/g;
> >
> > Below, is an example of problem text this code chokes on.
> >
> >           Example Text:    msgStop("", "Invalid date")
> >
> > 1.  The 1st set of Quotes have no contents and so it is
> >      simply  ignored.
> >
> > 2. The code then finds the next set of Quotes... which is  ", "
> >      NOTE: These Quotes do not belong to the same pair.
> >      The HTML formatting code is applied to the comma.
> >
> > 3.  Finally, the last set of Quotes are ignored because the
> >      code thinks there is only a single last Quote left.
> >
> > In this example (above), I would like the find only the last pair of quotes
> > and substitute its contents with the same text, plus the HTML formatting
> > code.
> >
> > Any help would be certainly appreciated.
>
>
> $TextBlockToConvert =~ s/"([^"]*)"/length $1 ? '"<FONT Color=BLUE>\1<\/Font>"' : 
> '""'/eg;

Hi John.

Almost right! But the deprecated \1 in the replacement string won't
work with the /e modifier: it needs to be $1. Although I'm sure you
knew that.

For a diversion, here's my submission

  $TextBlockToConvert =~ s{("[^"]*")} {
    qq($1 ? '<FONT Color="BLUE">$1<\/FONT>' : '$1')
  }eeg;

Which also corrects the HTML requirement for quotes around the
attribute values. Although, after all, the <FONT> tag itself is
deprecated in favour of CSS anyway! Can't win 'em all :)

Rob





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

Reply via email to