Rather than explain the following snippet should give you an idea of what I'm trying to do. I just can't quite get it going and respectfully ask for the help of the monks.

a) Is this right? I'm just trying to save writing the almost the same regex for every tag.
b) I can't figure out how to get the matched variables ($1, $2 etc..) into the text and I'm fresh out of ideas.

Code:
# ... my %taglist_complex = ( 'email' => "<a href='mailto:$1'>$2</a>", 'url' => "<a href='$1'>$2</a>", 'img' => "<img src='$1' alt='$2' />" ); my %taglist_simple = ( 'b' => '<b>$1</b>', 'i' => '<i>$1</i>', 'u' => '<u>$1</u>', 'url' => '<a href=\'$1\'>$1</a>', 'img' => '<img src=\'$1\' alt=\'$1\' />' ); # Process Complex Tags -> [url="http://www.foo.bar.com"]foobar[/ur +l] while (my ($tag, $regex) = each %taglist_complex) { $post =~ s/\[\s*$tag\s*=\s*['"]?([\w\W][^\]]*?)['"]?\](.[^\[|\ +]]*?)\[\s*\/\s*$tag\s*\]/$regex/gi; } # Process Simple Tags -> [url]http://www.foo.bar.com[/url] while (my ($tag, $regex) = each %taglist_simple) { $post =~ s/\[\s*$tag\s*\](.[^\[|\]]*?)\[\s*\/\s*$tag\s*\]/$reg +ex/gi; } #...

In reply to Drop in regex replacements? by IOrdy

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.