python 2.7 中阿拉伯语单词的正则表达式

Regular Expression for Arabic words in python 2.7

我使用 python 2.7,我想找到文本文件中单词的频率, 我使用以下表达式编写代码但没有输出:

    import nltk
    import os
    import re
    import string
    path="C:\Python27\Lib"
    os.chdir(path)
    frequency = {}
    document_text = open('1.txt', 'r')
    text_string = document_text.read().lower()
    match_pattern = re.findall(r'^[\u0621-\u064A\u0660-\u0669 ]+$', 
    text_string)

    for word in match_pattern:
         count = frequency.get(word,0)
         frequency[word] = count + 1

    frequency_list = frequency.keys()

    for words in frequency_list:
         print words, frequency[words]

这是因为你没有匹配所有 characters.If 你删除锚你会得到一个 match.See 演示。

https://regex101.com/r/uRdqZj/2