Here's another solution that uses only one very general regexp and an external handler:
while (<>) { s/\[([^=\]\/]+)(=([^\]]+))?\]([^\[]+)\[\/\1]/&handler($1,$3,$4)/eg +; print; } sub handler { my ($tag, $value, $data) = @_; for ( $tag ) { /img/ && return "<img src='$data'>"; /link/ && return "<a href='$value'>$data</a>"; } }
What's happening here is that every time perl encounters a bracketed tag, it extracts the tag name, value (if defined) and data (the text between the tags) and calls the sub handler which returns the replacement text.
An advantage here is that if you want to add more tags, you just have to edit the handler sub rather then generating a bunch of regular expressions that your text'll have to go through serially. A disadvantage is that, well, the regular expression might be a little confusing.
In reply to Re: User Code
by eg
in thread User Code
by Monolith-0
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |