我想用pyparsing編寫一個解析所有字符串包含特殊單詞的程序。我寫了下面的代碼,但它不工作:pyparsing:解析一個帶有特殊單詞的句子
from pyparsing import *
word = Word(alphas)
sentence = OneOrMore(word)
day = Literal("day")
sentence_end_with_happy = sentence + day + sentence
ret = sentence_end_with_happy.parseString("hi this is a nice day and everything is ok")
我試圖解析句子與「天」字的特殊但在分析它有錯誤...
pyparsing.ParseException:預期「day」(at char 42),(line:1,col:43)
的規則'sentence'消耗一切的字符串的結尾包括單詞 「天」 ... –