Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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中正则表达式在strcmp函数中的应用_C_Regex - Fatal编程技术网

c中正则表达式在strcmp函数中的应用

c中正则表达式在strcmp函数中的应用,c,regex,C,Regex,所以,我想尝试做的是用getline在一行中读取,并查找特定的阶段。如果我看到“verbose on”或“verbose off”之类的内容,我知道我要做什么,但是如果是“verbose”之类的内容,那么我想出错。我很确定这需要正则表达式,因为后面的内容是任意的。如果您能对这个问题有所了解,我们将不胜感激。多谢各位 strcmp(buf,"verbose on")==0 strcmp(buf,"verbose off")==0 strcmp(buf,"verbose "regex express

所以,我想尝试做的是用getline在一行中读取,并查找特定的阶段。如果我看到“verbose on”或“verbose off”之类的内容,我知道我要做什么,但是如果是“verbose”之类的内容,那么我想出错。我很确定这需要正则表达式,因为后面的内容是任意的。如果您能对这个问题有所了解,我们将不胜感激。多谢各位

strcmp(buf,"verbose on")==0
strcmp(buf,"verbose off")==0
strcmp(buf,"verbose "regex expression here im thinking"")==0

我想应该是这样的,只是需要一点推动

不需要正则表达式。您可以使用:

这只比较前7个字符,因此它将匹配任何以“verbose”开头的
buf

注意:我对魔法数字过敏,但如果您愿意,当然可以用文字
7
替换
strlen
调用。此外,对于实际代码,我将用常量替换重复的字符串文字

strncmp(buf, "verbose", strlen("verbose")) == 0