importre## . 通配符,一个 . 模糊匹配一个除换行符之外的任意字符#ret = re.findall('a..in', 'helloalvin')#print(ret) # ['alvin']#
## ^ 必须以某个字符开始#ret = re.findall('^a...n', 'alvinhelloawwwn')#print(ret) # ['alvin']#
## $ 必须以某个字符结尾#ret = re.findall('a...n$', 'alvinhelloawwwn')#print(ret) # ['awwwn']#
## * 贪婪匹配 [0, +oo]#ret = re.findall('abc*', 'abcccc') # 贪婪匹配[0,+oo]#print(ret) # ['abcccc']#
#ret = re.findall('a.*n', 'alvinhelloawwwn')#print(ret) # ['alvinhelloawwwn'] 贪婪匹配#
## + 贪婪匹配 [1, +oo]#ret = re.findall('abc+', 'abccc') # [1,+oo]#print(ret) # ['abccc']#
#ret = re.findall('a.+n', 'alvinhelloawwwn')#print(ret) # ['alvinhelloawwwn'] 贪婪匹配#
## ? 匹配[0,1]#ret = re.findall('abc?', 'abcccffab') # [0,1]#print(ret) # ['abc', 'ab']#
#{} 自定义重复次数 {1,} 表示一到正无穷
ret = re.findall('abc{1,4}', 'abcccccsccccc')print(ret) #['abcccc'] 贪婪匹配
#--------------------------------------------字符集[]
#ret = re.findall('a[bc]d', 'acd')#print(ret) # ['acd'] 匹配 b 或 c#
#ret = re.findall('[a-z]', 'acd')#print(ret) # ['a', 'c', 'd']#
#ret = re.findall('[.*+]', 'a.cd+')#print(ret) # ['.', '+'] # 在[]中,* + 失去原有的作用#
#在字符集里有功能的符号: - ^ \#
#ret = re.findall('[1-9]', '45dha3')#print(ret) # ['4', '5', '3']#
#^ 放在[]表示取反,不取 a 或 b 或 ,#ret = re.findall('[^ab,]', '45bdha3,')#print(ret) # ['4', '5', 'd', 'h', '3']#
#ret = re.findall('[\d]', '45bdha3')#print(ret) # ['4', '5', '3']
#\ 的功能#1、反斜杠后面跟元字符去除其特殊功能#2、反斜杠后面跟普通字符实现其特殊功能
'''\d 相当于 [0-9]
\D 相当于 [^0-9]
\s 匹配任何空白字符
\S 匹配任何非空字符
\w 匹配任何字母数字字符 [0-9a-zA-Z]
\W 匹配任何非字母数字字符 [^0-9a-zA-Z]
\b 匹配一个特殊字符边界,也就是指单词和空格间的位置'''
#ret=re.findall('I\b','I ')#print(ret)#[]
ret= re.findall('\dert','13ert')print(ret) #['3ert']
ret= re.findall('\Dert','13^ert')print(ret) #['^ert']
ret= re.findall('\s123', '123')print(ret)print(re.findall(r'I\b', 'hello,I am a hhI$hh'))print(re.findall(r'\bI', 'hello, I am a hhI$hh'))print(re.findall(r'\\', r'abf\vaf'))