in reply to Re: Re: Re: Re: Re: User Code
in thread User Code

That'll work, but I do want to point out one thing: you don't need a character class for a single character. :) $text =~  s#\[(https?://)?([^\|]+)\|([^\]]+)\]#<a href="$1$2">$3</a>#g;

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Re: User Code
by $code or die (Deacon) on Dec 11, 2000 at 19:19 UTC
    Good point! :)

    I also realised that it will only work if you type http:// or https://. It's nice to be able to leave out the http:// bit if you want it to default to http://

    So maybe you would have to do two regexes:
    $text =~ s#\[https://([^\|]+)\|([^\]]+)\]#<a href="https://$1">$2</a> +#g; $text =~ s#\[(http://)?([^\|]+)\|([^\]]+)\]#<a href="http://$2">$3</a +>#g
    Is there a simpler way of doing that?
      You could combine both of those regexps into one by doing something like this: s#\[(?:http(s)?://)?([^\|]+)\|([^\]]+)\]#<a href="http$1://$2">$3</a>#g;

      - Brad
        Nice one! Thanks!

        I didn't start this node and I think I managed to divert the topic somewhat, but have definitely been helped.