# 提取python
key ='javapythonc++php'print(re.findall('python', key)[0])# 提取hello world
key ='<html><h1>hello world</h1></html>'print(re.findall('<h1>(hello world)</h1>', key)[0])# 分组的方法# 提取170
string ='我喜欢cjv170的身高'print(re.findall('\d+', string)[0])# 提取http:// 和 https://
key ='http://www.baidu.com and https://bjv.com'print(re.findall('https?', key))# ?值前面一个字符出现过一次或0次# 提取hit.
key ='[email protected]'print(re.findall('h.*?\.', key))# ?切换贪婪模式# 提取sas和saas
key ='saas and sas and saaas'print(re.findall('sa{1,2}s', key))# 匹配i开头的行 re.S(单行匹配全部拉通) re.M(多行匹配)
string ='''fall in love with you
i love you ver much
i love she
i love her'''print(re.findall('^i.*', string, re.M))# 匹配全部行
string ='''<div>静夜思
窗前明月光
低头思故乡
</div>'''print(re.findall('<div>.*</div>', string, re.S))