python - 正则表达式用 Python 中的英文逗号替换中文标点符号
问题描述
解决方案
One way to do with re
module
import re
str='上海,北京、武汉;重庆。欢迎你!你好'
s = re.sub(r'[^\w\s]',',',str)
print(s)
Output:
上海,北京,武汉,重庆,欢迎你,你好
Explanation,
[^\w\s]
- Match a single character Not present in the list below-
1. \w matches any word character (equal to [a-zA-Z0-9_])
2. \s matches any whitespace character (equal to [\r\n\t\f\v ])
推荐阅读
- javascript - 将文本添加到多个 div 标签内的跨度
- java - 从 .jar 中发送和调用 .exe
- scala - 使用 Scala 在 Spark 中将数组转换为自定义字符串格式
- angularjs - 如何从spring控制器返回一个字符串值而不是java bean类
- python - 姜戈;如何过滤和使对象不同
- angular - 找不到本地工作区文件('angular.json')。但是相同的代码在另一台计算机上工作
- opentok - 如何在 opentok 会话中流式传输 mp3 文件而不是麦克风数据
- javascript - Mapbox GL JS:如何添加画布并从中获取数据?(天气图)
- angular - 如何以角度 6 将对象推入对象数组中
- process - 处理不与 Arduino uno 和控制台通信正在喷垃圾