我有一個數據的列表一個巨大的文件,如這樣:正則表達式匹配第一個和最後一個字或詞
#fabulous 7.526 2301 2
#excellent 7.247 2612 3
#superb 7.199 1660 2
#perfection 7.099 3004 4
#terrific 6.922 629 1
我有一個包含這樣的句子列表的文件:
Terrific Theo Walcott is still shit, watch Rafa and Johnny deal with him on Saturday.
its not that I'm a GSP fan, fabulous
Iranian general says Israel's Iron Dome can't deal with their missiles
with J Davlar 11th. Main rivals are team Poland.
我要檢查使用正則表達式如下:
如果在每一句第一個字相匹配的文件任何話例如,如果好棒,其,伊朗,與發生在文件中或不
如果在句子最後一個單詞匹配的文件 例的任何話,如果星期六,超讚,導彈,波蘭出現在文件中或不
如果2或3個字符前後綴的單個單詞在句子中匹配2或3個字符前綴和後綴在文件中 示例如果Ter,其,Ira,wi匹配任何2或3個單詞前綴文件與否。同樣適用於後綴。
我很新的正則表達式我能想到的這種方式,但沒有得到結果: term2.lower()是在文件中的第一列
wordanalysis["trail"] = found if re.match(sentence[-1],term2.lower()) else not(found)
wordanalysis["lead"] = found if re.match(sentence[0],term2.lower()) else not(found)
嗨@ r3mus請檢查我的編輯 – fscore
我想檢查第一個單詞是否與文件中的單詞列表匹配。爲什麼這有什麼不對?我正在開展一個項目。 – fscore
@ r3mus對不起。是的,你說得對。檢查我的編輯例子。 – fscore