python re sub
2011-06-22 17:36
495 查看
import
re
text = "JGood is a handsome boy, he is cool, clever, and so on..."
regex = re.compile(r'/w*oo/w*'
)
print
regex.findall(text)
#查找所有包含'oo'的单词
print
regex.sub(
lambda
m:
'['
+ m.group(
0
) +
']'
, text)
#将字符串中含有'oo'的单词用[]括起来。
re
text = "JGood is a handsome boy, he is cool, clever, and so on..."
regex = re.compile(r'/w*oo/w*'
)
regex.findall(text)
#查找所有包含'oo'的单词
regex.sub(
lambda
m:
'['
+ m.group(
0
) +
']'
, text)
#将字符串中含有'oo'的单词用[]括起来。
相关文章推荐
- python re.sub
- python re.sub
- python 文件游标以及 re 中的 match,sub(具体示例)
- python中使用re.sub更换倒数第一个字符串
- 【Python3 爬虫】09_正则表达式(re.math()、re.search()、re.sub()、全局匹配函数)
- python中的re.sub replace strip
- python正则表达式模块,re.sub的函数使用
- 转载: Python--详解Python中re.sub 作者:Mrzhoug
- 【整理】详解Python中re.sub
- python re.sub
- 详解Python中re.sub
- python 正则表达式 re.sub & re.subn
- Python:re.sub()实现字符串替换
- 关于python 的re.sub用法
- python基础===正则表达式,常用函数re.split和re.sub
- Python re.sub介绍
- python:re.sub简要分析
- python re.sub 正则匹配
- 详解Python中re.sub
- 转载-【整理】详解Python中re.sub