Lobsterpants Lobsterpants - 2 months ago 6
C# Question

Regular expression to remove {stuff in braces} and *

I am looking for a regular expression that will give me a clean string with tags in braces and * removed.

So that:

fredharry{john}barry*


gives:

fredharrybarry


there could be multiple tags so:

fredharry{john}barry{steve}{colin}terry/*


would give

fredharrybarryterry/


This is in c#

Thanks

Answer

This code works:

var patt = @"({\w+})|(\*)";
var myString = "fredharry{john}barry{steve}{colin}terry/*";
var newString = Regex.Replace(myString, patt, "");

See here.