Python论坛  - 讨论区

标题:[python-chinese] 正则式的问题

2007年04月27日 星期五 18:12

兵 周 sczhoubing在yahoo.com.cn
星期五 四月 27 18:12:26 HKT 2007

·Ç³£¸Ðл£¬ÕýÔòʽunicodeµÄ±ê־λÊÇʲô£¬ÎÒÊÇÐÂÊÖ :)

       
---------------------------------
 ÑÅ»¢Ãâ·ÑÓÊÏä3.5GÈÝÁ¿£¬20M¸½¼þ£¡
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070427/fec5b064/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年04月27日 星期五 18:28

limodou limodou在gmail.com
星期五 四月 27 18:28:18 HKT 2007

On 4/27/07, 兵 周 <sczhoubing在yahoo.com.cn> wrote:
> 非常感谢,正则式unicode的标志位是什么,我是新手 :)
>
标志为re.U,不过我试了一下,可以不用:

 >>> username = re.compile(ur'[\u4e00-\u9fa5]*\|\s')
 >>> print username.search(unicode("周兵|    122310980808123", 'gbk')) .group()
 周兵|

注意pattern使用了ur前缀,而且搜索串需要是unicode,当然结果也是unicode

-- 
I like python!
UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号