首页 > 编程语言 > 详细

python正则

时间:2020-11-03 21:56:05      阅读:38      评论:0      收藏:0      [点我收藏+]
import re

# findall
content = ‘this is a test falg!!!‘
pattern = re.compile(‘a (.*?) falg‘, re.S)
ret = re.findall(pattern, content)
print(ret)
[‘test‘]
# sub-----re.sub(pattern, repl, string, count, flags)
content = ‘this is a test falg!!!‘
ret = re.sub(‘a (.*?) falg‘, ‘a big flag‘, content)
print(ret)
this is a big flag!!!
# replace-----指定明确的old和new
content = ‘this is a test falg!!!‘
ret = content.replace(‘test‘, ‘big‘)
print(ret)
this is a big falg!!!

python正则

原文:https://www.cnblogs.com/hui-code/p/13922774.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!