in reply to RE: Using code posted on PerlMonks
in thread Using code posted on PerlMonks

That's a nice point. I threw this code together rather quickly, so I didn't think of all possibilities. That last regex could definitely use some beefing up and I think you've given it a good start. Thanks for the feedback!

Just a quick (untested) stab:

s/<a href="[^"]+">([^<]+)<\/a>/[$1]/g;
This is pretty generic and I would only use it in this context because there is an assumption that the data will be more or less valid. I think it would catch most cases. Also, I dropped a set of parentheses. I have no frickin' idea why I had them in the first place.

Cheers,
Ovid

Update: I've now tested this regex modification and it appears to work fine. I also realized a potential bug in the code that would be rare, but difficult to circumvent: if someone names a sub "amp" (or another HTML character code name) and tries to call the sub with '&amp;', this code will cheefully convert that to '&' and the resulting code will not function properly.

Update #2: buzzcutbuddha pointed out that the "Bug" I mentioned wasn't behaving quite the way I posted. It will only occur if someone names a subroutine "amp" and then posts the code without code tags. Highly unlikely, but a possibility.

Replies are listed 'Best First'.
RE: RE: RE: Using code posted on PerlMonks
by buzzcutbuddha (Chaplain) on Jul 11, 2000 at 16:28 UTC
    in response to your update, wouldn't you actually get
    &amp;amp;
    in ASCII/escaped HTML if someone named a subroutine amp?

    To check for the above use
    /\&(amp;)($1)/
    and you would catch it. Just a quick thought. :)