Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在寻找最好的方法来纠正字符串中单词的潜在拼写错误,而不考虑标点符号。我不想在进行评估之前剥离它,因为这会改变最终编辑的字符串。我当前的方法在将字符串拆分为空格后使用 py-enchant(.check() 方法),但这不会忽略标点符号。
misspelled_string = 'This is a (tesl strung.'
期望的输出:
corrected_string = 'This is a (test string.'
尝试除以任何不是字母的东西,使用re:
re
import re misspelled_string = 'This is a (tesl strung.' res=re.split(r"[^\w]+", misspelled_string)
输出:
>>> res ['This', 'is', 'a', 'tesl', 'strung', '']