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.


In reply to RE: RE: Using code posted on PerlMonks by Ovid
in thread Using code posted on PerlMonks by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.