I’m currently facing a (little) blocking issue. I’d like to replace a substring by one another using regular expression. But here is the trick : I suck at regex.
Regex.Replace(contenu, "Request.ServerVariables("*"))",
"ServerVariables('test')");
Basically I’d like to replace whatever is between the ” by “test”. I tried “.{*}” as a pattern but it doesn’t work.
Could you give me some tips, I’d appreciate it!
There are several issues you need to take care of.
., parens, quotes) — you need to escape these with a slash. And you need to escape the slashes with another slash as well because we ‘re in a C# string literal, unless you prefix the string with@in which case the escaping rules are different..*. In this case, you would want to match any number of non-quote characters, which is[^"]*.The end result is