我有一個類似2頁長的文本文件,我需要編寫一個正則表達式來提取以大寫字母開頭的單詞。 ,我想獲得(但不限於)有些詞的例子是:以大寫字母開頭的單詞的正則表達式
British Indian Ocean Territory
People's Republic of China Confederation of Independent States
French Southern and Antarctic Lands
Gilbert and Ellia Islands
Iraq-Saudia Arabia Neutral Zone
Juan de Nova Island
St. Vincent and the Grenadines
Trust Territory of the Pacific
Washington, D.C.
,我想出了正則表達式是:
"((?:[A-Z][a-z]+\\s){2,4}?) || ((?:[A-Z][a-z]+\\s){1,2}of(?:\\s[A-Z][a-z]+){1,2}) || ((?:[A-Z][a-z]+\\s){1,2}and(?:\\s[A-Z][a-z]+){1,2})"
恭喜。那對你有用嗎? – 2013-11-26 18:54:31
那麼......這個正則表達式有什麼問題嗎?如果是這樣,什麼? – ajp15243
你試圖做的事情對正則表達式來說是不可能的,因爲你似乎想要提取的不僅是單個單詞而是表達式(例如:「中華民國獨立國家聯合會」)。請記住,不使用字典是不可能的。 –