in reply to Converting custom mark-up to HTML

Yep! Read up on 'numbered match variables' in perlre. They can be used as in the following:

use strict; use warnings; while (<DATA>) { s/\[image=([\w\.]+)\]/<img src="$1">/; s/\[color=([\w#]+)\]/<font color="$1">/; s/\[link=([\w:\/\.]+)\]/<a class="my_link" href="$1">/; print; } __DATA__ Hey have a look at this [image=var.jpg] Insert a [color=#99CC99] [link=http://www.perlmonks.net] to the site

Be warned, though, that what you're attempting to do might not be the best way to achieve what it is that you're trying to achieve. Are there any closing tags available for your bracketed markup?

Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"

Replies are listed 'Best First'.
Re: Re: Converting custom mark-up to HTML
by bkiahg (Pilgrim) on Apr 19, 2004 at 17:48 UTC
    Thank you Art_XIV, thats exactly what I was looking for!

    What would be a better way of doing this? I was looking for a way to strip html and still offer some simple formatting.

    I do add closing tags, right after the opening tags.
    s/\[\/color\]/<\/font>/gi; s/\[\/link\]/<\/a>/gi;