![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
正则表达式-regular expression
文章平均质量分 73
liucheng_zimozigreat
这个作者很懒,什么都没留下…
展开
-
python中一次替换字符串中的多个字符
知识传送门:正则表达式先直接上解决方案:比如下面给出的字符串a,有字母、'(单引号)、\n(换行符)、数字、:(冒号)、,(逗号),目标是只保留字符串中的数字和字母,且看我如何操作。import rea='eew \' eawr,2 fd\n sa:21'b=re.sub(r'[\':\s ,]*', '', a) # 前面是正则表达式,匹配多种字符(串)print(b)...原创 2018-12-29 15:51:54 · 46162 阅读 · 9 评论 -
固定长度切分字符串-regular expression
文章目录使用固定长度切分字符串替换掉字符串中的空格使用固定长度切分字符串>>> import re>>> s1='2142142343'>>> re.findall(r'.{2}', s1)['21', '42', '14', '23', '43']替换掉字符串中的空格>>> import re>&...原创 2019-03-22 10:45:40 · 429 阅读 · 0 评论 -
python-TypeError: cannot use a string pattern on a bytes-like object
错误表现: 写程序时报错TypeError: cannot use a string pattern on a bytes-like object 查了好多处,起初以为是我的文件是二进制保存的,但是在Notepad++中将其改为UTF-8编码后问题依旧出现。下面是报错那行的代码,此行想要将四个值转换成str类型:group.loc[idx, 'TCID'] = str(group.loc...原创 2019-05-04 20:22:24 · 12792 阅读 · 1 评论