Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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
如何创建正则表达式来查找没有大括号的C代码块?_C_Regex - Fatal编程技术网

如何创建正则表达式来查找没有大括号的C代码块?

如何创建正则表达式来查找没有大括号的C代码块?,c,regex,C,Regex,我需要一个正则表达式来查找C语言中的代码块,出于代码安全原因,这些代码块应该始终与大括号(if、for、do、while…)一起使用 例如: 我需要匹配: if (a) anything 但不是: if (a) { anything } Tried to create it using a negative lookahead pattern but did not work: \tif\(*.*\n\t*(?!\{).* This will be used on Visua

我需要一个正则表达式来查找C语言中的代码块,出于代码安全原因,这些代码块应该始终与大括号(if、for、do、while…)一起使用

例如: 我需要匹配:

if (a)
   anything
但不是:

if (a)
{
    anything
}

Tried to create it using a negative lookahead pattern but did not work: \tif\(*.*\n\t*(?!\{).*

This will be used on Visual Studio Code.

Any suggestions?

正则表达式无法做到这一点。可能
\bif\s*\([^()]*\)\n(?!\t*\{)。*
()?我知道你已经看到了这个建议,你有时间检查它吗?在VSCode上试过了,但不起作用。它将if块与{匹配。