I need to write this IronPython code in C# (I couldn’t find a similar C# library to match IronPython’s re module):
for v in variables:
replace = re.compile(v, re.IGNORECASE)...
re.sub(v, str(self.SQLVariables[v.upper().replace("&","")]),script_content)...
In other words, what is the C# equivalent to the following expressions:
- re.compile(…)…
- re.sub(…)…
Your question boils down to, how do I use regular expressions in C#?
The answer is the
Regexclass. To perform a replacement you needRegex.Replace(). There is no need to explicitly compile the regex because that is done when you create theRegexinstance.The following example from MSDN illustrates how to use the class: