in reply to Re: Drop in regex replacements?
in thread Drop in regex replacements?

Sorry, I thought it would be quite obvious because above each regex is an example of what I am parsing. :-(
# Process Complex Tags -> [url="http://www.foo.bar.com"]foobar[/url]
What you suggested would be longer than just cutting/pasting and running a complete regex for every tag. shame.

Replies are listed 'Best First'.
Re: Re: Re: Drop in regex replacements?
by Joost (Canon) on Sep 09, 2002 at 15:07 UTC
    Please read my above explanation for what I am doing here.

    I am changing the problem around to make it easier to maintain and expand. If you really need to have compact code, you can change the &replace sub like this:

    my %replaces = ( email => sub { "<a href=mailto:'$_[0]'>$_[1]</a>" }, url => sub { "<a href='$_[0]'>$_[1]</a>'" }, # etc etc etc ); sub replace { my ($tag,$attr,$content) = @_; $attr ||= $content; return $replaces{$tag}->($attr,$content); }
    I was merely trying to make the code as clean and clear as I could.
    -- Joost downtime n. The period during which a system is error-free and immune from user input.