我想創建一個匹配任何小寫字母的正則表達式,但不包括'return'和'while',是否可以這樣做?我不想解決這樣的:正則表達式匹配小寫字詞,但使用Flex排除某些單詞(快速詞法分析器)
return {/*nothing*/}
while {/*nothing*/}
[a-z]+ {/*some code*/}
我想創建一個匹配任何小寫字母的正則表達式,但不包括'return'和'while',是否可以這樣做?我不想解決這樣的:正則表達式匹配小寫字詞,但使用Flex排除某些單詞(快速詞法分析器)
return {/*nothing*/}
while {/*nothing*/}
[a-z]+ {/*some code*/}
我不是你想要的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.
這是我爲FLEX找到的一些文檔。它沒有提及單詞邊界'\ b'或負面預測'(?!regex)'。 http://flex.sourceforge.net/manual/Patterns.html#Patterns –
嗯,我知道你的意思,也許你的答案會在一些正則表達式系統中工作,但flex不支持「!」和「\ b」 – xudifsd
此文檔是否支持您的FLEX版本? http://flex.sourceforge.net/manual/Patterns.html#Patterns –
不,我的版本是flex 2.5.35 – xudifsd
我看了上面的評論中的文檔,並且找不到辦法去做,除了你描述。你爲什麼不接受? –