正则表达式匹配小写单词,但使用Flex(快速词法分析器)排除某些单词

时间:2011-07-15 03:51:37

标签: regex flex-lexer

我想创建一个正则表达式以匹配任何小写单词但排除'return'和'while',是否可以这样做?我不想这样解决:

return {/*nothing*/}
while {/*nothing*/}
[a-z]+ {/*some code*/}

1 个答案:

答案 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.