I've googled some code that converts an url into a hyperlink using bbcode The code is :
// format the url tags: [url=www.website.com]my site[/url]
// becomes: <a href="www.website.com">my site</a>
exp = new Regex(@"\[url\=([^\]]+)\]([^\]]+)\[/url\]");
str = exp.Replace(str, "<a href=\"$1\">$2</a>");
// format the img tags: [img]www.website.com/img/image.jpeg[/img]
// becomes: <img src="www.website.com/img/image.jpeg" />
exp = new Regex(@"\[img\]([^\]]+)\[/img\]");
str = exp.Replace(str, "$1\" />");
I also want to convert ordinary links hyperlinks.I've googled some more and got this:
exp = new Regex("(http://[^ ]+)");
str = exp.Replace(str, "<a href=\"$1\">$1</a>");
The problem is, when i mix them and third regular expression is executed, the first two will be messed up. as it could result in :
<img src="<a href='www.website.com/img/image.jpeg>www.website.com/img/image.jpeg</a>" />
how can i specify in my third regular expression that he cannot convert strings that begin with 'href="' or 'src="' ?