Re
普通网友
这个作者很懒,什么都没留下…
展开
-
Python中的Re找到字符串包含字符的所有位置
python字符串有find,index, rindex, 都是只能查找一次字符串出现的位置,就是没有查找字符串中包含某个字符的所有位置。#-*-coding:utf8-*-import relist=[i.start() for i in re.finditer('\\\\', 'C:\\Users\\aaa\\computer\\flicker\\01213.jpg')]print(li...原创 2018-06-11 13:41:23 · 23982 阅读 · 3 评论 -
正则表达式去除中文标点符号并且获取数字
#-*-coding:utf8-*-import refile=open("D:/资料/山西/data_no_null.txt","r",encoding="utf8")all_word=[["全水"],["分析水"],["灰分"],["挥发"],["固定碳"],["焦渣特征"],["硫"],["原创 2018-07-04 15:03:34 · 4075 阅读 · 0 评论 -
Python正则表达式Re中findall
findall中()里面的内容是需要捕获的内容,但是如果我们想捕获整个正则表达式的结果则需要添加如下代码:#-*-coding:utf8-*-import restr1 = "[email protected]@[email protected]@asdfcom"a=re.findall(r"\w+@(qq|163|126)\.com",str1)print(a)b=re....原创 2019-01-03 10:24:59 · 2699 阅读 · 0 评论 -
Python中.*和.*?的区别
.*和.*?表达式 .* 的意思很好理解,就是单个字符匹配任意次,即贪婪匹配。表达式 .*? 是满足条件的情况只匹配一次,即懒惰匹配#-*-coding:utf8-*-import repattern_1 = re.compile(".*([1-9]\\d*|[一两二三四五六七八九十]{1,3})(百|千|)米.*")pattern_2 = re.compile(".*?([1...原创 2019-05-20 15:00:48 · 15092 阅读 · 3 评论