简体   繁体   English

用于检测未用双引号括起来的单词和字符串的正则表达式

[英]A regex to detect a word and a string that is not enclosed in double quotes

I have tried to write a regular expression for the an example code to use in grep search.我试图为示例代码编写一个正则表达式,以在 grep 搜索中使用。

My requirement is to get string output that matches only the below我的要求是获得仅与以下匹配的字符串输出

execute(any word here)执行(这里的任何词)

For eg.例如。

execute(any)
execute(math)

and the results should not output结果不应该输出

execute("any")
execute("math")

I already tried the following, but the problem with this is that it outputs everything and doesn't give me the required solution.我已经尝试了以下方法,但问题在于它输出了所有内容并且没有给我所需的解决方案。

grep -E '^execute\(*([^)]+)*\)'

I expect my output to be execute(math) or execute(s) and not我希望我的输出是 execute(math) 或 execute(s) 而不是

execute("math") or execute("s")执行(“数学”)或执行(“s”)

Based on your limited sample data, this should work:根据您有限的样本数据,这应该有效:

^execute\([a-zA-Z]+\)$

https://regex101.com/r/S4owrs/2 https://regex101.com/r/S4owrs/2

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

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