Re: 字符串中的查找问题

"li liu" <[email protected]>
Newsgroups gmane.comp.python.chinese
Message-ID <[email protected]>
The re <file:///D:/Users/cn1ll290/Desktop/python/lib/module-re.html> module
provides regular expression tools for advanced string processing. For
complex matching and manipulation, regular expressions offer succinct,
optimized solutions:

re <file:///D:/Users/cn1ll290/Desktop/python/lib/module-re.html>模块为高级字符串处理提供了正则表达式工具。对于复杂的匹配和处理,正则表达式提供了简洁、优化的解决方案。

>>> import re
>>> re.findall(r'\bf[a-z]*', 'which foot or hand fell fastest')
['foot', 'fell', 'fastest']
>>> re.sub(r'(\b[a-z]+) \1', r'\1', 'cat in the the hat')
'cat in the hat'

 When only simple capabilities are needed, string methods are preferred
because they are easier to read and debug:

如果只需要简单的功能,应该首先考虑字符串方法,因为它们非常简单,易于阅读和调试。

>>> 'tea for too'.replace('too', 'two')
'tea for two'



在08-1-17,小龙 <[email protected]> 写道:
>
>  谢谢~~ 原来那么简单~~ 那re里的 search是什么作用?
>
>
> _______________________________________________
> python-chinese
> Post: send [email protected]
> Subscribe: send subscribe to [email protected]
> Unsubscribe: send unsubscribe to  [email protected]
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>

_______________________________________________
python-chinese
Post: send [email protected]
Subscribe: send subscribe to [email protected]
Unsubscribe: send unsubscribe to  [email protected]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.