I have this code for replace the content between ()
Regex yourRegex = new Regex(@"\(([^\)]+)\)");
//Example strings
string rep1 yourRegex.Replace("This is a (variable) string.", ""); //yields "This is a string."
Result is "This is a string."
but i have this string "This is a [variable] string". Now how to use Regex for same replace method?
String.Replaceif you're coding for the general case RegEx has no chance of working and the implementation is far more complicated. To reliably parse a Context Free Language you need some implementation of a PDA (RegEx is an implementation of an NFA).(variable)as a keyword of sorts. Fair enough.