sub()方法

sub()方法:替换符合规律的内容,返回替换的值

# -?- coding: utf-8 -?-
import re

secret_code = 'wwwfhskdjwww'

secret_code_new = re.sub('www(.*?)www', 'www.aobosir.www', secret_code )
print(secret_code_new)

运行

www.aobosir.www

上面的代码也也可以写成这个样子,替换格式化字符串。使用占位符

# -?- coding: utf-8 -?-
import re

secret_code = 'wwwfhskdjwww'

secret_code_new = re.sub('www(.*?)www', 'www%swww'%'.aobosir.', secret_code )
print(secret_code_new)

运行

www.aobosir.www

参考网站:
http://www.jikexueyuan.com/course/777_2.html?ss=2

相关文章:

  • 2021-06-22
  • 2022-03-07
  • 2022-12-23
  • 2021-08-11
  • 2022-12-23
  • 2022-12-23
  • 2021-07-24
  • 2021-05-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2022-12-23
  • 2021-05-18
相关资源
相似解决方案