开发者

Regex to match lower case words but exclude certain words using Flex (The Fast Lexical Analyzer)

i want to create a regex to match any lower case words but exclude 'return' and 'while', is it possible to do this? i don't want to solve like this:

return {/*nothing*/}
while {/*nothin开发者_如何学编程g*/}
[a-z]+ {/*some code*/}


I'm not 100% clear on what you want, but this might be helpful:

\b(?!(?:return|while)\b)[a-z]+

It matches

\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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜