my first production regex for jesse

2007-08-25 @ 17:19#

i got to put my regex gains to work today for jesse's machina site. he uses snitz for his forum services. i helped him tie in the user-password functionality from sitz for the rest of his site, too (kinda cool). anyway, snitz uses forum codes for inline markup - kinda funky, but it's pretty common. but he wanted to display some of that snitz content in his own site pages. bummer of it is that all 'forum code' will appear 'as is' - it will not be translated into the proper HTML on his pages. so in i leap!

as a simple start, i wrote a regex that converts [url="http://somesite.com"]go here[/url] into <a href="http://somesite.com">go here</a>. pretty simple. the regex looks like this:

\[url=&quot;(.+)&quot;\](.+)\[/url\]

notice the &quot;? that's because we're applying this regex within XSLT - EXSLT, actually. the markup looks like this now:

<xsl:value-of 
    select="regexp:replace(
        Body,
        '\[url=&quot;(.+)&quot;\](.+)\[/url\]',
        'g:i:',
        '&lt;a href=&quot;$1&quot;&gt;$2&lt;/a&gt;')" 
     disable-output-escaping="yes"
/>

kinda gnarly, once you see it all put together. and i will admit, it took me a couple tries to get it working properly. but now that it works, it's pretty cool!

code