views:

81

answers:

1

I'm trying to remove all BBCode Tags from a string.

[url]www.google.com[/url]

becomes

www.google.com

I have a regex that works in php to find them all, just dont know how to remove them in .net

RegEx to Find BBCode

|[[\/\!]*?[^\[\]]*?]|si
+2  A: 

Your regular expression looks like it won't work so I tried a different one:

string s = "[url]www.google.com[/url] [url=www.google.com]www.google.com[/url]";
s = Regex.Replace(s, @"\[[^]]+\]", "");

Result:

www.google.com www.google.com

Also, you will need this using statement at the top of your file to make this work:

using System.Text.RegularExpressions;
Mark Byers
What about BBCode tags like this [url=www.google.com]Google[/url] ?
Landmine
@Tyler: See updated answer.
Mark Byers
Thank you very much, you're a life saver.
Landmine