How to implement \p{L} in python regex

后端 未结 1 1366
一整个雨季
一整个雨季 2020-12-21 01:12

I was trying to match all the string that contain one word in any language. My search led me to \\p{...} which was absent in python\'s Re module. But I found https://pypi.py

相关标签:
1条回答
  • 2020-12-21 02:08

    You should pass unicode. (Both regular expression and the string)

    import sys
    
    import regex
    
    
    def main(patterns):
        patterns = [regex.compile(p) for p in patterns]
        for line in sys.stdin:
            line = line.decode('utf8')
            for regexp in patterns:
                if regexp.search (line):
                    print line.strip('\n')
    
    if __name__ == '__main__':
        main([ur'^\d+\t(\p{L}|\p{M})+$', ])
    
    0 讨论(0)
提交回复
热议问题