zoukankan      html  css  js  c++  java
  • Python匹配中文的正则表达式

    
    python 中的字符串:   https://www.cnblogs.com/livingintruth/p/3282981.html
    
    
    
    # -*- coding: utf-8 -*-
    import re
    def findPart(regex, text, name):
    res=re.findall(regex, text)
    if res:
    print "There are %d %s parts:
    "% (len(res), name)
    for r in res:
    print "	",r.encode("utf8")
    print
    text ="#who#helloworld#a中文x#"
    usample=unicode(text,'utf8')
    findPart(u"#[wu2E80-u9FFF]+#", usample, "unicode chinese")
    
    
    注:
    
    几个主要非英文语系字符范围
    2E80~33FFh:中日韩符号区。收容康熙字典部首、中日韩辅助部首、注音符号、日本假名、韩文音符,中日韩的符号、标点、带圈或带括符文数字、月份,以及日本的假名组合、单位、年号、月份、日期、时间等。
    3400~4DFFh:中日韩认同表意文字扩充A区,总计收容6,582个中日韩汉字。
    4E00~9FFFh:中日韩认同表意文字区,总计收容20,902个中日韩汉字。
    A000~A4FFh:彝族文字区,收容中国南方彝族文字和字根。
    AC00~D7FFh:韩文拼音组合字区,收容以韩文音符拼成的文字。
    F900~FAFFh:中日韩兼容表意文字区,总计收容302个中日韩汉字。
    FB00~FFFDh:文字表现形式区,收容组合拉丁文字、希伯来文、阿拉伯文、中日韩直式标点、小符号、半角符号、全角
    
    
    import re
    message = u'天人合一'.encode('utf8')
    print(re.search(u'人'.encode('utf8'), message).group())
    交互模式下的例子
    >>> import re
    >>> s='Phone No. 010-87654321'
    >>> 
    >>> r=re.compile(r'(d+)-(d+)')
    >>> m=r.search(s)
    >>> m
    <_sre.SRE_Match object at 0x010EE218>
    
    
  • 相关阅读:
    一个网站架构的变迁
    网络编程
    http协议篇
    第1篇 编程能力是什么
    django中的cookies和session机制
    django的认证与授权系统
    python的异常处理
    第0篇
    mysql优化和全局管理杂记
    k8s中pod的资源配置详解
  • 原文地址:https://www.cnblogs.com/nyist-xsk/p/9156774.html
Copyright © 2011-2022 走看看