天天看點

python怎麼判斷标點_Python正規表達式标點識别

我被這個難住了。我隻是在學習正規表達式,不明白為什麼它不會傳回标點符号。在

以下是正規表達式正在解析的文本檔案:

4月/NNP

是/VBZ

日期

最殘酷/JJ

月/NN

,/,

育種/VBG

丁香/NNP

輸出/RB

共/英寸

日期

死亡/JJ

土地/NNtext = open_file.read()

grammarList = raw_input("Enter your grammar string: ");

tags = grammarList.split("^")

tags_pattern = r'\s+'.join(r"([\w\,\:\;\"\-\.]+)/{0}".format(re.escape(tag)) for tag in tags) + r"\b"

print tags_pattern

from re import findall

start_position = 0

for poem in poemList:

start_position = text.find('', start_position)

end_position = text.find('' + poem + '>', start_position)

searchtext = text [start_position:end_position]

poemname = poem

for oldname, newname in poemtitleswapList.items():

poemname = poemname.replace(oldname, newname)

print (poemname)

print (findall(tags_pattern, searchtext))

print ("\n")

我以為方括号裡的“\,”可以讓它傳回一個“,”,但它不起作用。在

任何幫助都将不勝感激。在