Perl/Regex question (hopefully simple)

Madison Kelly linux-5ZoueyuiTZhBDgjK7y7TUQ at public.gmane.org
Tue Jun 29 16:33:39 UTC 2004


Devin Whalen wrote:
> On Tue, 2004-06-29 at 11:56, Madison Kelly wrote:
> 
>>Hi all,
>>
>>   I'm not having a lot of luck googling for the answer to this 
>>question. I hope someone can help or point me in the right direction 
>>(like what perldoc to read).
>>
>>   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>
>>
>>I was trying something like this but it isn't working...
>>
>>$help_body =~ s/\[url=(.*)\](.*)\[\/url\]/(<a href=").*(" 
>>target="_new">).*(<\/a>)/gi;
>>
>>So how do I go about substituting values around variable information 
>>that I want to save?
>>
>>Thanks!!
>>
>>Madison
>>--
>>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
> 
> 
> Dam, sorry to do this but I forget my second set of ()
> so change it to:
> $url=~s/\[url=(.*?)\](.*)\[\/url\]/<a href="$1" target="_new">$2<\/a>/g;
> 
> I knew I shouldn't have rushed and sent the code :).
> 
> Later
> 
> 

Thank you Devin and Phillip!!

As is often the (frustrating) case just after sending the email I found 
the answer... Here is what I did:

$help_body =~ s/\[url=(.*)\](.*)\[\/url\]/<a href="\1" 
target="_new">\2<\/a>/gi;

Which seems very much like what you both recommended. Do you know if one 
method is better or worse than the other or are they just two ways to do 
the same thing?

Thank you both very much!!

Madison
--
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