我想创建一个正则表达式以匹配任何小写单词但排除'return'和'while',是否可以这样做?我不想这样解决:
return {/*nothing*/}
while {/*nothing*/}
[a-z]+ {/*some code*/}
答案 0 :(得分:0)
我不是100%明确你想要什么,但这可能会有所帮助:
\b(?!(?:return|while)\b)[a-z]+
匹配
\b # A word break.
(?!(?:return|while)\b) # This is a negative look around
# saying don't match if a return
# or while is matched followed by
# a word break.
[a-z]+ # Match 1 or more lowercase letters.