Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract and process data out of [code] tags using regular expressions 1

Status
Not open for further replies.

Zhris

Programmer
Aug 5, 2008
254
GB
I need to be able to check if a message contains [link] tags and then replace them with the appropriate html code.

E.g.
Code:
The link to Google is [link]http://google.com[/url] !!!
=
The link to Google is <a href="[URL unfurl="true"]http://google.com"[/URL] target="_blank">[URL unfurl="true"]http://google.com</a>[/URL] !!!

I am very weak whilst writing regexes and this one has really gone over the top of my head. Any help or links to help would really be appreciated.

Code:
sub command_link {
	$link_ = $_[0];
	my $link = '<a href="'.$link_.'" target="_blank">'.$link_.'</a>';
	return $link;
}

if ($message =~ m/^\[link\](?)+\[\/link\]$/) { $message = command_link(m/^\[link\](.$)\[\/link\]$/); }

Thanks
 
Hi,

Thank you, thats cleared up a few things.

All my "commands" (subroutines) are stored in a separate library file and I sort of wanted to be consistent with this. This is partially because the user has the ability to append/edit the library file (add/edit commands).

Is there any practical way I could pass $1 into the subroutine?

Thanks
 
Absolutely perfect *****

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top