in reply to Re: Linking words in html to glossary.
in thread Linking words in html to glossary.

Doh! You are right. I missed that one somehow. He's also trying to solve a slightly different problem. I can skip the stiff in the quotes (href="..."). I want to skip the stuff beteen <a href="..."> and </a>. I also forgot that I will be doing this inside of an XML::Parser. So I will know when I'm inside the tag. (That's what I get for trying to test new ideas in a seperate program :) )

I am still interested in how this would work using a regex (or two or three). The node you linked didn't mention much in the comments on how to do that. I don't think the solutions mentioned there would work. I suspect some very fun lookahead and/or lookbehind stuff but I have not used those options before.

PerlStalker

  • Comment on Re: Re: Linking words in html to glossary.

Replies are listed 'Best First'.
Re: Re: Re: Linking words in html to glossary.
by lshatzer (Friar) on Jul 20, 2001 at 02:47 UTC
    Ahhh, okay. Sorry about that. If you look at my reply in that node, I mention a method that uses a negative lookahead. Play around with it a little. And as always, read perlre :o)

      Yeah. Now that I've looked at it a bit more, something kinda like this should work:

      $file =~ s/(\s+)($word)([\.\?\!]?\s+).*?(?!</a>)/"$1<a href=\"".$gloss +ary{$word}{'link'}."\">$2<\/a>$3"/eig;

      The .*(?!</a>) should then say that the engine will match the word plus (optionally) stuff after it unless that mess is ended by a </a>.

      PerlStalker