简体   繁体   English

在正则表达式中包含花括号以查找C#方法定义

[英]Include Curly braces in Regular Expression to find C# Methods Definition

Using this regular expression to find methods of C#. 使用此正则表达式查找C#的方法。 \\w+(([^)]+))|\\w+(()) with this I get the method name and parameters, I need to include the character "{" to be sure that is the definition of a method. \\ w +(([[^)] +))| \\ w +(())可以得到方法名称和参数,我需要包含字符“ {”以确保它是方法的定义。 View Image 看图片

You can place the pattern into a non-capturing group ( (?:...) ) and then add { : 您可以将模式放入非捕获组( (?:...) ),然后添加{

(?:\w+\(([^)]+)\)|\w+\(()\))[\p{Zs}\t]*{
^^^                        ^           ^

See demo 观看演示

Note that [\\p{Zs}\\t]* matches 0 or more horizontal whitespace symbols in .NET. 请注意, [\\p{Zs}\\t]*与.NET中的0个或多个水平空白符号匹配。

Also note that { does not have to be escaped in a .NET regex. 还要注意{不必在.NET正则表达式中转义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM