Is there equivalent to \Q ... \E in C# Regex
Is there equivalen开发者_Go百科t to \Q ... \E in C# Regex? I can't find it.
There is no direct equivalent to the \Q...\E syntax in .NET as told on this site.
Instead you could use the Regex.Escape method :
Escapes a minimal set of characters (\, *, +, ?, |, {, [, (,), ^, $,., #, and white space) by replacing them with their escape codes.
Can use Regex.Escape
string input = "any +idea? dude";
string pattern = @"\ *" + Regex.Escape("+idea?") + @"\ *"
Regex Expression = new Regex(pattern);
MatchCollection match = Expression.Matches(input);
精彩评论