简体   繁体   English

Visual Studio 正则表达式模式不起作用:^.*Foo[^.,]\(+.*$

[英]Visual studio regex pattern does not work : ^.*Foo[^.,]\(+.*$

I have following lines of code,我有以下几行代码,

int Foo(char);

int Foo()
{
//do something
}

int FooBar(char, char);
foo.Get();
fooBar.Get();
m_FooBar.Get();
case foo:
fooBar(x,y);

I want to search only for function reference, declaration and definition with 'Foo' name.我只想搜索带有“Foo”名称的 function 参考、声明和定义。 Only four of the above lines to be shown in result结果中仅显示上述四行

  1. int Foo(char); int Foo(char);
  2. int Foo()整数 Foo()
  3. int FooBar(char, char); int FooBar(char, char);
  4. fooBar(x,y); fooBar(x,y);

I tried我试过了

^.*Foo[^.,]\(+.*$

But it also selected case Foo:但它也选择了案例 Foo:

Whats wrong with this regex?这个正则表达式有什么问题?

You may use您可以使用

^.*Foo\w*\(+.*$

Make sure you make it case insensitive, as shown in this regex demo .确保你让它不区分大小写,如这个正则表达式演示中所示。 The [^.,] part is a negated character class, and it matches any char that is not a dot and comma, it might match a line break char. [^.,]部分是一个否定字符 class,它匹配任何不是点和逗号的字符,它可能匹配换行字符。 With \w , you only match [A-Za-z0-9_] characters.使用\w ,您只能匹配[A-Za-z0-9_]字符。

Details细节

  • ^ - start of string (line in text editors) ^ - 字符串开头(文本编辑器中的行)
  • .* - any 0+ chars other than line break chars, as many as possible .* - 除换行符以外的任何 0+ 个字符,尽可能多
  • Foo - a Foo word Foo - 一个Foo
  • \w* - 0 or more letters, digits, _ s \w* - 0 个或多个字母、数字、 _ s
  • \(+ - 1 or more ( chars \(+ - 1 或更多(字符
  • .* - any 0+ chars other than line break chars, as many as possible .* - 除换行符以外的任何 0+ 个字符,尽可能多
  • $ - end of string (line in text editors). $ - 字符串结尾(文本编辑器中的行)。

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

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