IOrdy has asked for the wisdom of the Perl Monks concerning the following question:
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:
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; } #...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Drop in regex replacements?
by Ovid (Cardinal) on Sep 09, 2002 at 15:02 UTC | |
by IOrdy (Friar) on Sep 09, 2002 at 16:41 UTC | |
Re: Drop in regex replacements?
by Joost (Canon) on Sep 09, 2002 at 14:50 UTC | |
by IOrdy (Friar) on Sep 09, 2002 at 14:58 UTC | |
by Joost (Canon) on Sep 09, 2002 at 15:07 UTC | |
Re: Drop in regex replacements?
by zigdon (Deacon) on Sep 09, 2002 at 14:31 UTC | |
by IOrdy (Friar) on Sep 09, 2002 at 14:42 UTC | |
Re: Drop in regex replacements?
by Util (Priest) on Sep 09, 2002 at 19:43 UTC |
Back to
Seekers of Perl Wisdom