开发者

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

开发者 https://www.devze.com 2023-03-20 16:59 出处:网络
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:

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

精彩评论

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