2005年11月01日 星期二 21:34
一个规则表达式r'\d\d',搜索条件还包括两个数字相等,有什么办法?谢谢! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20051101/16645cb3/attachment.htm
2005年11月01日 星期二 22:08
正则表达式不支持复杂的匹配,如带逻辑的东西。。 如果非要正则表达式完成这个。。 用最笨的方法咯。。 把所有可能都罗列出来 On 11/1/05, Gu Yingbo <tensiongyb at gmail.com> wrote: > > 一个规则表达式r'\d\d',搜索条件还包括两个数字相等,有什么办法?谢谢! > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20051101/83b16fe0/attachment.html
2005年11月01日 星期二 22:22
试试
import re
r = re.compile(r'(\d)\1')
print r.match('12')
print r.match('11')
在 05-11-1,Gu Yingbo<tensiongyb at gmail.com> 写道:
> 一个规则表达式r'\d\d',搜索条件还包括两个数字相等,有什么办法?谢谢!
>
> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
>
>
>
2005年11月01日 星期二 22:29
r = re.compile(r'^(\d{1})\1$')
这样写更严格
在 05-11-1,wolfg<wolfg1969 at gmail.com> 写道:
> 试试
> import re
> r = re.compile(r'(\d)\1')
> print r.match('12')
> print r.match('11')
>
> 在 05-11-1,Gu Yingbo<tensiongyb at gmail.com> 写道:
> > 一个规则表达式r'\d\d',搜索条件还包括两个数字相等,有什么办法?谢谢!
> >
> > _______________________________________________
> > python-chinese list
> > python-chinese at lists.python.cn
> > http://python.cn/mailman/listinfo/python-chinese
> >
> >
> >
>
2005年11月01日 星期二 22:34
分组还可这样用?刚开始发言就闹笑话了。。。 郁闷。。 On 11/1/05, wolfg <wolfg1969 at gmail.com> wrote: > > r = re.compile(r'^(\d{1})\1$') > 这样写更严格 > > 在 05-11-1,wolfg<wolfg1969 at gmail.com> 写道: > > 试试 > > import re > > r = re.compile(r'(\d)\1') > > print r.match('12') > > print r.match('11') > > > > 在 05-11-1,Gu Yingbo<tensiongyb at gmail.com> 写道: > > > 一个规则表达式r'\d\d',搜索条件还包括两个数字相等,有什么办法?谢谢! > > > > > > _______________________________________________ > > > 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 > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20051101/13265839/attachment.html
2005年11月01日 星期二 22:45
非常感谢!本来想不行的话就更改策略了,这下省事不少. 在05-11-1,wolfg <wolfg1969 at gmail.com> 写道: > > 试试 > import re > r = re.compile(r'(\d)\1') > print r.match('12') > print r.match('11') > > 在 05-11-1,Gu Yingbo<tensiongyb at gmail.com> 写道: > > 一个规则表达式r'\d\d',搜索条件还包括两个数字相等,有什么办法?谢谢! > > > > _______________________________________________ > > 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 > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20051101/a13a6034/attachment.htm
2005年11月02日 星期三 09:57
再问一个问题:如果后一个数字=前一个数字+1该怎么办? 在05-11-1,wolfg <wolfg1969 at gmail.com> 写道: > > 试试 > import re > r = re.compile(r'(\d)\1') > print r.match('12') > print r.match('11') > > 在 05-11-1,Gu Yingbo<tensiongyb at gmail.com> 写道: > > 一个规则表达式r'\d\d',搜索条件还包括两个数字相等,有什么办法?谢谢! > > > > _______________________________________________ > > 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 > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20051102/24a9f2a8/attachment.html
2005年11月02日 星期三 10:17
在 05-11-2,Gu Yingbo<tensiongyb at gmail.com> 写道: > 再问一个问题:如果后一个数字=前一个数字+1该怎么办? http://www.regexlib.com/default.aspx 自个儿搜索吧……………… > 在05-11-1,wolfg <wolfg1969 at gmail.com> 写道: > > 试试 > > import re > > r = re.compile(r'(\d)\1') > > print r.match('12') > > print r.match('11') > > > > 在 05-11-1,Gu Yingbo<tensiongyb at gmail.com> 写道: > > > 一个规则表达式r'\d\d',搜索条件还包括两个数字相等,有什么办法?谢谢! > > > > > > _______________________________________________ > > > 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 > > > -- # Time is unimportant, only life important! ## 面朝开源,我心自由!
2005年11月02日 星期三 10:20
正则表达式可以干这个么? 你可以用其它的方式啊 比如从外面传进来一个数,自己计算出来,再用正则表达式去找啊 在 05-11-2,Gu Yingbo<tensiongyb at gmail.com> 写道: > 再问一个问题:如果后一个数字=前一个数字+1该怎么办? > > 在05-11-1,wolfg <wolfg1969 at gmail.com> 写道: > > 试试 > > import re > > r = re.compile(r'(\d)\1') > > print r.match('12') > > print r.match('11') > > > > 在 05-11-1,Gu Yingbo<tensiongyb at gmail.com> 写道: > > > 一个规则表达式r'\d\d',搜索条件还包括两个数字相等,有什么办法?谢谢! > > > > > > _______________________________________________ > > > 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 > > >
2005年11月02日 星期三 10:22
regular expressions are not panacea!
pat = r"(\d)(\d)"
m = re.search(pat, txt)
if m :
   if int(m.group(2)) - int(m.group(1)) == 1 :
       pass
(Sorry, using Linux, no ime installed)
On 11/1/05, Gu Yingbo <tensiongyb at gmail.com> wrote:
> 再问一个问题:如果后一个数字=前一个数字+1该怎么办?
>
> 在05-11-1,wolfg <wolfg1969 at gmail.com> 写道:
> > 试试
> > import re
> > r = re.compile(r'(\d)\1')
> > print r.match('12')
> > print r.match('11')
> >
> > 在 05-11-1,Gu Yingbo<tensiongyb at gmail.com> 写道:
> > > 一个规则表达式r'\d\d',搜索条件还包括两个数字相等,有什么办法?谢谢!
> > >
> > > _______________________________________________
> > > 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
>
>
>
2005年11月02日 星期三 10:23
这个恐怕做不到了,俺在想想 在 05-11-2,Gu Yingbo<tensiongyb at gmail.com> 写道: > 再问一个问题:如果后一个数字=前一个数字+1该怎么办? > > 在05-11-1,wolfg <wolfg1969 at gmail.com> 写道: > > 试试 > > import re > > r = re.compile(r'(\d)\1') > > print r.match('12') > > print r.match('11') > > > > 在 05-11-1,Gu Yingbo<tensiongyb at gmail.com> 写道: > > > 一个规则表达式r'\d\d',搜索条件还包括两个数字相等,有什么办法?谢谢! > > > > > > _______________________________________________ > > > 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号