How to remove BBCode from string in .Net

I am 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 for BBCode Search

|[[\/\!]*?[^\[\]]*?]|si

      

+2


a source to share


1 answer


Your regex looks like it won't work, so I tried something else:

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 instruction located at the top of the file to make this work:

using System.Text.RegularExpressions;

      

+2


a source







All Articles