开发者

Is there equivalent to \Q ... \E in C# Regex

开发者 https://www.devze.com 2022-12-22 14:12 出处:网络
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.

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号