Perl/Regex question (hopefully simple)
Stewart C. Russell
scruss-rieW9WUcm8FFJ04o6PK0Fg at public.gmane.org
Tue Jun 29 17:00:37 UTC 2004
Madison Kelly wrote:
>
> I am trying to do a regex substitute where I need to maintain two
> pieces of dynamic data. Specifically I am trying to convert some keys
> into a proper html link. For example, I want to convert:
>
> [url=groups.google.ca]Google Groups[/url]
>
> into
>
> <a href="groups.google.ca" target="_new">Google Groups</a>
If you can't find a pre-built BBCode parser to do all the gruntwork for
you, this is the small and simple solution that I'd use:
s,\[\/url\],</a>,ig;
s,\[url=([^\]]+)\],<a href="$1" target="_new">,ig;
This allows the URL to be split over multiple lines, which is hard to
catch with an all-in-one approach.
cheers,
Stewart
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list