参考博客:https://www.cnblogs.com/tina-python/p/5508402.html

这里说一下python的re模块即正则表达式模块,先列出其中涉及到的各种字符和模式等:

一、字符:

python中的正则表达式--re模块

python中的正则表达式--re模块

python中的正则表达式--re模块

二、re.sub(pattern , repl , string)格式说明:

pattern:即正则化的格式,一般是 :   r'.....'   ;

string: 源字符串;

repl:我们用repl字符串来替换使用pattern在string匹配到的部分;

同时,该函数返回的也是匹配替换后的字符串;

PS:

(1)\w+可以匹配任意长度的字符串;

(2)依然可以用编号来索引特殊分组,即(?P...);

(3)如果没有匹配到,则返回原字符串;

 

相关文章:

  • 2021-08-13
  • 2021-12-09
  • 2022-01-02
  • 2021-08-23
  • 2021-12-19
  • 2021-07-30
  • 2021-11-05
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-17
  • 2022-12-23
  • 2021-12-18
  • 2021-12-26
  • 2021-05-14
相关资源
相似解决方案