#re模块
import re
# ret = re.findall('w\w{2}l', 'hello world')
# print(ret) #['worl']
#2元字符:. ^ $ * + ? {} [] | () \
# .通配符
# ret = re.findall('w..l', 'hello world')
# print(ret) #['worl'] .只能代指任意一个字符
# ret = re.findall('w..l', 'hello w\nld')
# print(ret) #[] 匹配不了\n
# ^尖角符
# ret = re.findall('^h...o', 'sdsdslijlkjhello')
# print(ret) #[] ^只以字符串的开始做匹配
# $符
# ret = re.findall('h...o$', 'sdsdslijlkjhello')
# print(ret) #['hello'] 只以结尾做匹配
# *符
# ret = re.findall('h.*o', 'wdsadsadhreosadlkjaslkdhlloasldkjahhoh')
# print(ret) #['hreosadlkjaslkdhlloasldkjahho'] *符重复匹配
#
# ret = re.findall('ba*', 'skldjslkjbaaaaaa')
# print(ret) #['baaaaaa']
# +符
# ret = re.findall('ho+', 'slkdjlskajdheeoholkjl')
# print(ret) #['ho']
# ret = re.findall('a+b', 'skdjskjdaaaaaabbbbbsdsd')
# print(ret) #['aaaaaab']
# ?符
# ret = re.findall('a?b', 'skdjskjdaaaaaabbbbbsdsd')
# print(ret) #['ab', 'b', 'b', 'b', 'b']
# {}符
# ret = re.findall('a{5}b', 'aaaaab')
# print(ret) #['aaaaab'] {}决定次数
#
# ret = re.findall('a{1,3}b', 'abaabaaab')
# print(ret) #['ab', 'aab', 'aaab'] {}决定范围
# [] 字符集
# ret = re.findall('a[c,d]x','acx')
# print(ret) #['acx']或的意思
# ret = re.findall('a[c,d]x','adx')
# print(ret)#['adx']
# ret = re.findall('a[c,d]x','acdx')
# print(ret)#[]
# ret = re.findall('[a-z]','abc')
# print(ret) #['a', 'b', 'c'] 表示一个范围
#
# ret = re.findall('[w,*]','asdwsd*')
# print(ret)#['w', '*'] 取消元字符的特殊功能(除 \ ^ - )
#
# ret = re.findall('[^a]','sdsdabba')
# print(ret)#['s', 'd', 's', 'd', 'b', 'b']匹配除了a以为的所有元素
# \ 后面跟特殊字符去除特殊功能,后面跟部分普通字符实现特殊功能
#\d匹配任何十进制的数[0-9]
#print(re.findall('\d{11}','asdasd18672190001'))#['18672190001']
#\D匹配任何非数字字符[^0-9]
#\s匹配任何空白字符
#print(re.findall('\sasd','f asd'))#[' asd']
#print(re.findall('\sasd','fasd'))#[]
#\S匹配任何非空白字符
#\w匹配任何数字字母字符[a-zA-Z0-9]
#\W匹配任何非数字字母字符[^a-zA-Z0-9]
#\b匹配任何一个特殊字符边界,也就是单词和空格间的位置
#print(re.findall(r'i\b','hello,i am a man'))#['i']
#search 匹配出满足条件的第一个结果
#ret = re.search('sb', 'sdsdsdsbslkjsb')
#print(ret)#<_sre.SRE_Match object; span=(6, 8), match='sb'>
#print(ret.group())#sb
print(re.search('a.', 'abcac').group())#ab
print(re.search('a\.', 'a.bcac').group())#a.