开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜