2005年04月05日 星期二 22:30
使用了一下,感觉不错。 但还是不知道怎么完成多行匹配,即要匹配的模式可能在一行上也可能在多行上,而且分行的位置不是很确定。 --- Jacob Fan <jacob at exoweb.net> wrote: > 请看re模块的文档, 其中module content一节. > 逸飞 张 wrote: > > > > 有相关的module还是使用re模块,替换之类的功能怎么实现。 > > 请举个例子,谢谢。 > > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > _________________________________________________________ Do You Yahoo!? 150万曲MP3疯狂搜,带您闯入音乐殿堂 http://music.yisou.com/ 美女明星应有尽有,搜遍美图、艳图和酷图 http://image.yisou.com 1G就是1000兆,雅虎电邮自助扩容! http://cn.rd.yahoo.com/mail_cn/tag/1g/*http://cn.mail.yahoo.com/event/mail_1g/
2005年04月06日 星期三 09:33
import re
m = re.match(r".*(\d\n\d).*", '3.14\n3.14', re.M)
print m.groups()
结果:
('4\n'3,)
re.M是多行标志,详见Python Document。
逸飞 张 写道:
>使用了一下,感觉不错。
>但还是不知道怎么完成多行匹配,即要匹配的模式可能在一行上也可能在多行上,而且分行的位置不是很确定。
>--- Jacob Fan <jacob at exoweb.net> wrote:
>
>
>>请看re模块的文档, 其中module content一节.
>>逸飞 张 wrote:
>>
>>
>>
>有相关的module还是使用re模块,替换之类的功能怎么实现。
>
>
>>>请举个例子,谢谢。
>>>
>>>
>>_______________________________________________
>>python-chinese list
>>python-chinese at lists.python.cn
>>http://python.cn/mailman/listinfo/python-chinese
>>
>>
>>
>
>_________________________________________________________
>Do You Yahoo!?
>150万曲MP3疯狂搜,带您闯入音乐殿堂
>http://music.yisou.com/
>美女明星应有尽有,搜遍美图、艳图和酷图
>http://image.yisou.com
>1G就是1000兆,雅虎电邮自助扩容!
>http://cn.rd.yahoo.com/mail_cn/tag/1g/*http://cn.mail.yahoo.com/event/mail_1g/
>_______________________________________________
>python-chinese list
>python-chinese at lists.python.cn
>http://python.cn/mailman/listinfo/python-chinese
>
>
>
>
--
座右铭:不怕不会,就怕不会搜!
提点建议:大家把自己的邮件客户端设置一下,这里好多邮件是乱码,如果你们看到我的邮件是乱码,也请通知我一下,以免影响交流。
2005年04月06日 星期三 10:16
一些regular的tips:
1 ?非贪婪flag
>>> re.findall(r"a(\d+?)", "a23b")
['2']
>>> re.findall(r"a(\d+)", "a23b")
['23']
注意比较这种情况:
>>> re.findall(r"a(\d+)b", "a23b")
['23']
>>> re.findall(r"a(\d+?)b", "a23b")
['23']
2 如果你要多行匹配,那么加上re.S和re.M标志
re.S:.将会匹配换行符,默认.不会匹配换行符
>>> re.findall(r"a(\d+)b.+a(\d+)b", "a23b\na34b")
[]
>>> re.findall(r"a(\d+)b.+a(\d+)b", "a23b\na34b", re.S)
[('23', '34')]
>>>
re.M:^$标志将会匹配每一行,默认^和$只会匹配第一行
>>> re.findall(r"^a(\d+)b", "a23b\na34b")
['23']
>>> re.findall(r"^a(\d+)b", "a23b\na34b", re.M)
['23', '34']
但是,如果没有^标志,
>>> re.findall(r"a(\d+)b", "a23b\na23b")
['23', '23']
可见,是无需re.M
-----Original Message-----
From: python-chinese-bounces at lists.python.cn
[mailto:python-chinese-bounces at lists.python.cn] On Behalf Of 逸飞 张
Sent: Tuesday, April 05, 2005 10:31 PM
To: python-chinese at lists.python.cn
Subject: Re: [python-chinese] python中怎么实现sed的功能
使用了一下,感觉不错。
但还是不知道怎么完成多行匹配,即要匹配的模式可能在一行上也可能在多行上,
而且分行的位置不是很确定。
--- Jacob Fan <jacob at exoweb.net> wrote:
> 请看re模块的文档, 其中module content一节.
> 逸飞 张 wrote:
>
> >
>
有相关的module还是使用re模块,替换之类的功能怎么实现。
> > 请举个例子,谢谢。
>
>
> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
>
_________________________________________________________
Do You Yahoo!?
150万曲MP3疯狂搜,带您闯入音乐殿堂
http://music.yisou.com/
美女明星应有尽有,搜遍美图、艳图和酷图
http://image.yisou.com
1G就是1000兆,雅虎电邮自助扩容!
http://cn.rd.yahoo.com/mail_cn/tag/1g/*http://cn.mail.yahoo.com/event/ma
il_1g/
_______________________________________________
python-chinese list
python-chinese at lists.python.cn
http://python.cn/mailman/listinfo/python-chinese
2005年04月06日 星期三 11:08
如何匹配中文? On Apr 6, 2005 10:16 AM, lifr <lifr_sh at yeah.net> wrote: > > 一些regular的tips: > > 1 ?非贪婪flag > >>> re.findall(r"a(\d+?)", "a23b") > ['2'] > >>> re.findall(r"a(\d+)", "a23b") > ['23'] > > 注意比较这种情况: > >>> re.findall(r"a(\d+)b", "a23b") > ['23'] > >>> re.findall(r"a(\d+?)b", "a23b") > ['23'] > > 2 如果你要多行匹配,那么加上re.S和re.M标志 > re.S:.将会匹配换行符,默认.不会匹配换行符 > >>> re.findall(r"a(\d+)b.+a(\d+)b", "a23b\na34b") > [] > >>> re.findall(r"a(\d+)b.+a(\d+)b", "a23b\na34b", re.S) > [('23', '34')] > >>> > > re.M:^$标志将会匹配每一行,默认^和$只会匹配第一行 > >>> re.findall(r"^a(\d+)b", "a23b\na34b") > ['23'] > >>> re.findall(r"^a(\d+)b", "a23b\na34b", re.M) > ['23', '34'] > > 但是,如果没有^标志, > >>> re.findall(r"a(\d+)b", "a23b\na23b") > ['23', '23'] > 可见,是无需re.M > > -----Original Message----- > From: python-chinese-bounces at lists.python.cn > [mailto:python-chinese-bounces at lists.python.cn] On Behalf Of 逸飞 张 > Sent: Tuesday, April 05, 2005 10:31 PM > To: python-chinese at lists.python.cn > Subject: Re: [python-chinese] python中怎么实现sed的功能 > > 使用了一下,感觉不错。 > 但还是不知道怎么完成多行匹配,即要匹配的模式可能在一行上也可能在多行上, > 而且分行的位置不是很确定。 > --- Jacob Fan <jacob at exoweb.net> wrote: > > 请看re模块的文档, 其中module content一节. > > 逸飞 张 wrote: > > > > > > > > 有相关的module还是使用re模块,替换之类的功能怎么实现。 > > > 请举个例子,谢谢。 > > > > > > _______________________________________________ > > python-chinese list > > python-chinese at lists.python.cn > > http://python.cn/mailman/listinfo/python-chinese > > > > _________________________________________________________ > Do You Yahoo!? > 150万曲MP3疯狂搜,带您闯入音乐殿堂 > http://music.yisou.com/ > 美女明星应有尽有,搜遍美图、艳图和酷图 > http://image.yisou.com > 1G就是1000兆,雅虎电邮自助扩容! > http://cn.rd.yahoo.com/mail_cn/tag/1g/*http://cn.mail.yahoo.com/event/ma > il_1g/ > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > -- 鹦鹉聪明绝顶、搞笑之极,是人类的好朋友。 直到有一天,我才发觉,我是鹦鹉。 我是翻墙的鹦鹉。
2005年04月06日 星期三 11:59
可以看看这个参考一下 http://leejd.cndev.org/archive/2005/02/20/7132.aspx On Wed, 6 Apr 2005 11:08:07 +0800 could ildg <could.net at gmail.com> wrote: > 如何匹配中文? > > On Apr 6, 2005 10:16 AM, lifr <lifr_sh at yeah.net> wrote: > > > > 一些regular的tips: > > > > 1 ?非贪婪flag > > >>> re.findall(r"a(\d+?)", "a23b") > > ['2'] > > >>> re.findall(r"a(\d+)", "a23b") > > ['23'] > > > > 注意比较这种情况: > > >>> re.findall(r"a(\d+)b", "a23b") > > ['23'] > > >>> re.findall(r"a(\d+?)b", "a23b") > > ['23'] > > > > 2 如果你要多行匹配,那么加上re.S和re.M标志 > > re.S:.将会匹配换行符,默认.不会匹配换行符 > > >>> re.findall(r"a(\d+)b.+a(\d+)b", "a23b\na34b") > > [] > > >>> re.findall(r"a(\d+)b.+a(\d+)b", "a23b\na34b", re.S) > > [('23', '34')] > > >>> > > > > re.M:^$标志将会匹配每一行,默认^和$只会匹配第一行 > > >>> re.findall(r"^a(\d+)b", "a23b\na34b") > > ['23'] > > >>> re.findall(r"^a(\d+)b", "a23b\na34b", re.M) > > ['23', '34'] > > > > 但是,如果没有^标志, > > >>> re.findall(r"a(\d+)b", "a23b\na23b") > > ['23', '23'] > > 可见,是无需re.M > > > > -----Original Message----- > > From: python-chinese-bounces at lists.python.cn > > [mailto:python-chinese-bounces at lists.python.cn] On Behalf Of 逸飞 张 > > Sent: Tuesday, April 05, 2005 10:31 PM > > To: python-chinese at lists.python.cn > > Subject: Re: [python-chinese] python中怎么实现sed的功能 > > > > 使用了一下,感觉不错。 > > 但还是不知道怎么完成多行匹配,即要匹配的模式可能在一行上也可能在多行上, > > 而且分行的位置不是很确定。 > > --- Jacob Fan <jacob at exoweb.net> wrote: > > > 请看re模块的文档, 其中module content一节. > > > 逸飞 张 wrote: > > > > > > > > > > > > 有相关的module还是使用re模块,替换之类的功能怎么实现。 > > > > 请举个例子,谢谢。 > > > > > > > > > _______________________________________________ > > > python-chinese list > > > python-chinese at lists.python.cn > > > http://python.cn/mailman/listinfo/python-chinese > > > > > > > _________________________________________________________ > > Do You Yahoo!? > > 150万曲MP3疯狂搜,带您闯入音乐殿堂 > > http://music.yisou.com/ > > 美女明星应有尽有,搜遍美图、艳图和酷图 > > http://image.yisou.com > > 1G就是1000兆,雅虎电邮自助扩容! > > http://cn.rd.yahoo.com/mail_cn/tag/1g/*http://cn.mail.yahoo.com/event/ma > > il_1g/ > > _______________________________________________ > > python-chinese list > > python-chinese at lists.python.cn > > http://python.cn/mailman/listinfo/python-chinese > > > > > > _______________________________________________ > > python-chinese list > > python-chinese at lists.python.cn > > http://python.cn/mailman/listinfo/python-chinese > > > > > > > > > -- > 鹦鹉聪明绝顶、搞笑之极,是人类的好朋友。 > 直到有一天,我才发觉,我是鹦鹉。 > 我是翻墙的鹦鹉。 > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese -- saddle <saddle at gmail.com>
2005年04月06日 星期三 12:27
没有匹配过中文。 -----Original Message----- From: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] On Behalf Of could ildg Sent: Wednesday, April 06, 2005 11:08 AM To: python-chinese at lists.python.cn Subject: Re: [python-chinese] 我使用正则表达式的一点总结 如何匹配中文? On Apr 6, 2005 10:16 AM, lifr <lifr_sh at yeah.net> wrote: > > 一些regular的tips: > > 1 ?非贪婪flag > >>> re.findall(r"a(\d+?)", "a23b") > ['2'] > >>> re.findall(r"a(\d+)", "a23b") > ['23'] > > 注意比较这种情况: > >>> re.findall(r"a(\d+)b", "a23b") > ['23'] > >>> re.findall(r"a(\d+?)b", "a23b") > ['23'] > > 2 如果你要多行匹配,那么加上re.S和re.M标志 > re.S:.将会匹配换行符,默认.不会匹配换行符 > >>> re.findall(r"a(\d+)b.+a(\d+)b", "a23b\na34b") > [] > >>> re.findall(r"a(\d+)b.+a(\d+)b", "a23b\na34b", re.S) > [('23', '34')] > >>> > > re.M:^$标志将会匹配每一行,默认^和$只会匹配第一行 > >>> re.findall(r"^a(\d+)b", "a23b\na34b") > ['23'] > >>> re.findall(r"^a(\d+)b", "a23b\na34b", re.M) > ['23', '34'] > > 但是,如果没有^标志, > >>> re.findall(r"a(\d+)b", "a23b\na23b") > ['23', '23'] > 可见,是无需re.M > > -----Original Message----- > From: python-chinese-bounces at lists.python.cn > [mailto:python-chinese-bounces at lists.python.cn] On Behalf Of 逸飞 张 > Sent: Tuesday, April 05, 2005 10:31 PM > To: python-chinese at lists.python.cn > Subject: Re: [python-chinese] python中怎么实现sed的功能 > > 使用了一下,感觉不错。 > 但还是不知道怎么完成多行匹配,即要匹配的模式可能在一行上也可能在多行 上, > 而且分行的位置不是很确定。 > --- Jacob Fan <jacob at exoweb.net> wrote: > > 请看re模块的文档, 其中module content一节. > > 逸飞 张 wrote: > > > > > > > > 有相关的module还是使用re模块,替换之类的功能怎么实现。 > > > 请举个例子,谢谢。 > > > > > > _______________________________________________ > > python-chinese list > > python-chinese at lists.python.cn > > http://python.cn/mailman/listinfo/python-chinese > > > > _________________________________________________________ > Do You Yahoo!? > 150万曲MP3疯狂搜,带您闯入音乐殿堂 > http://music.yisou.com/ > 美女明星应有尽有,搜遍美图、艳图和酷图 > http://image.yisou.com > 1G就是1000兆,雅虎电邮自助扩容! > http://cn.rd.yahoo.com/mail_cn/tag/1g/*http://cn.mail.yahoo.com/event/ > ma > il_1g/ > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > -- 鹦鹉聪明绝顶、搞笑之极,是人类的好朋友。 直到有一天,我才发觉,我是鹦鹉。 我是翻墙的鹦鹉。 _______________________________________________ python-chinese list python-chinese at lists.python.cn http://python.cn/mailman/listinfo/python-chinese
Zeuux © 2025
京ICP备05028076号