Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用regex匹配regextest(dontcare、dontcare、true)_Regex - Fatal编程技术网

使用regex匹配regextest(dontcare、dontcare、true)

使用regex匹配regextest(dontcare、dontcare、true),regex,Regex,我想使用正则表达式来查找所有函数调用(c++,但不重要),其中函数是用3个参数调用的,最后一个参数具有特定值 例如,我想搜索对regextest的所有调用,其中使用3个参数调用,第三个参数为“true” regextest(aaa,bbb,true) : OK regextest(aaa,ccc,false) : NOK, third parameter is not 'true' regextest(aaa,bbb,true,false) : NOK four parameters are u

我想使用正则表达式来查找所有函数调用(c++,但不重要),其中函数是用3个参数调用的,最后一个参数具有特定值

例如,我想搜索对regextest的所有调用,其中使用3个参数调用,第三个参数为“true”

regextest(aaa,bbb,true) : OK
regextest(aaa,ccc,false) : NOK, third parameter is not 'true'
regextest(aaa,bbb,true,false) : NOK four parameters are used

如果参数本身不能包含任何逗号,请使用

regextest\([^(),]+,[^(),]+,true\)
说明:

regextest\(#匹配“regextest(”
[^(),]+#匹配一个或多个字符,但不匹配括号/逗号
,#匹配逗号
[^(),]+#(见上文)
,true\)#匹配,true)”

请注意,在匹配正则表达式时,空格非常重要-如果在正则表达式的最后一部分中有空格,您可能需要使用
,\s*true\s*)
,如果
true

需要更多信息。我们能否确定逗号仅作为参数分隔符出现在函数调用中?或者它们可能是参数的一部分,好像
regextest(foo,“bar,baz”,bam)
?如果除了作为参数分隔符的作用之外没有逗号出现,那么请尝试以下模式:
\([^,]+,[^,]+,\s*false\s*\)
。。。它似乎工作得很好。在本例中,逗号仅显示为分隔符