python里使用正则表达式来替换匹配成功的组
2023-09-14 09:10:35 时间
在前面主要学习了怎么样匹配成功,都没有修改原来的内容的。现在来学习一个匹配成功之后修改相应的内容,在这里使用sub()函数来实现这个功能,同时使用引用组号来插入原来的字符,例子如下:
结果输出如下:
Text: Make this **cai**. This **junsheng**.
深入浅出Numpy
五子棋游戏开发
http://edu.csdn.net/course/detail/5487
#python 3.6
#蔡军生
#http://blog.csdn.net/caimouse/article/details/51749579
#
import re
bold = re.compile(r'\*{2}(.*?)\*{2}')
text = 'Make this **cai**. This **junsheng**.'
print('Text:', text)
print('Bold:', bold.sub(r'<b>\1</b>', text))
结果输出如下:
Text: Make this **cai**. This **junsheng**.
Bold: Make this <b>cai</b>. This <b>junsheng</b>.
深入浅出Numpy
http://edu.csdn.net/course/detail/6149
Python游戏开发入门
你也能动手修改C编译器
纸牌游戏开发
http://edu.csdn.net/course/detail/5538
五子棋游戏开发
http://edu.csdn.net/course/detail/5487
RPG游戏从入门到精通
http://edu.csdn.net/course/detail/5246
WiX安装工具的使用
http://edu.csdn.net/course/detail/5207
俄罗斯方块游戏开发
http://edu.csdn.net/course/detail/5110
boost库入门基础
http://edu.csdn.net/course/detail/5029
Arduino入门基础
http://edu.csdn.net/course/detail/4931
Unity5.x游戏基础入门
http://edu.csdn.net/course/detail/4810
TensorFlow API攻略
http://edu.csdn.net/course/detail/4495
TensorFlow入门基本教程
http://edu.csdn.net/course/detail/4369
C++标准模板库从入门到精通
http://edu.csdn.net/course/detail/3324
跟老菜鸟学C++
http://edu.csdn.net/course/detail/2901
跟老菜鸟学python
http://edu.csdn.net/course/detail/2592
在VC2015里学会使用tinyxml库
http://edu.csdn.net/course/detail/2590
在Windows下SVN的版本管理与实战
http://edu.csdn.net/course/detail/2579
Visual Studio 2015开发C++程序的基本使用
http://edu.csdn.net/course/detail/2570
在VC2015里使用protobuf协议
http://edu.csdn.net/course/detail/2582
在VC2015里学会使用MySQL数据库
http://edu.csdn.net/course/detail/2672
相关文章
- Python爬虫之正则表达式的使用(三)
- Python爬虫从入门到精通——基本库re的使用:正则表达式
- Python正则简单实例分析
- Python排序搜索基本算法之归并排序实例分析
- Python正则表达式如何进行字符串替换实例
- 玩转python爬虫之正则表达式
- python正则表达式
- Python爬虫开发:正则表达式re的使用
- 一名python学习者打开双11的正确姿势
- Python:利用pandas对两个dataframe数据进行左联接/左关联(以左边为主体)、右联接/右关联(以右边为主体)、内联接(取交集)、外联接(取并集)操作案例实现代码
- Python每日一练——第30天:正则表达式练习
- python爬虫怎么副业接单
- 〖Python语法进阶篇⑫〗- 正则表达式的综合小练习
- Python爬虫从入门到精通——基本库re的使用:正则表达式
- 深度盘点:30个用于深度学习、自然语言处理和计算机视觉的顶级 Python 库
- 【阶段三】Python机器学习19篇:机器学习项目实战:AdaBoost分类模型
- python使用pandas读取excel
- Python编程:operator模块包含的函数
- Python: 正则表达式匹配反斜杠 ""
- python里预先编译正则表达式提高效率
- python里使用正则表达式的内嵌功能选项标志
- python里使用正则表达式的选项参数
- 被吹的神乎其神的Python到底都能干什么学习
- python基础之使用os.system来执行系统命令