更新时间2019-04-01 09:17:43
re.findall(r"#(.*abc.*)#", target_string)
正则 re.findall 的简单用法(返回string中所有与pattern相匹配的全部字串,返回形式为数组)
语法:
1findall(pattern, string, flags=0)
123regular_v1 = re.findall(r"docs","https://docs.python.org/3/whatsnew/3.6.html")print (regular_v1)# ['docs']
123regular_v2 = re.findall(r"^https","https://docs.python.org/3/whatsnew/3.6.html")print (regular_v2)# ['https']
123regular_v3 = re.findall(r"html$","https://docs.python.org/3/whatsnew/3.6.html")print (regular_v3)# ['html']
123regular_v4 = re.findall(r"[t,w]h","https://docs.python.org/3/whatsnew/3.6.html")print (regular_v4)# ['th', 'wh']
123456regular_v5 = re.findall(r"d","https://docs.python.org/3/whatsnew/3.6.html")regular_v6 = re.findall(r"ddd","https://docs.python.org/3/whatsnew/3.6.html/1234")print (regular_v5)# ['3', '3', '6']print (regular_v6)# ['123']
123regular_v7 = re.findall(r"D","https://docs.python.org/3/whatsnew/3.6.html")print (regular_v7)# ['h', 't', 't', 'p', 's', ':', '/', '/', 'd', 'o', 'c', 's', '.', 'p', 'y', 't', 'h', 'o', 'n', '.', 'o', 'r', 'g', '/', '/', 'w', 'h', 'a', 't', 's', 'n', 'e', 'w', '/', '.', '.', 'h', 't', 'm', 'l']
123regular_v8 = re.findall(r"w","https://docs.python.org/3/whatsnew/3.6.html")print (regular_v8)#['h', 't', 't', 'p', 's', 'd', 'o', 'c', 's', 'p', 'y', 't', 'h', 'o', 'n', 'o', 'r', 'g', '3', 'w', 'h', 'a', 't', 's', 'n', 'e', 'w', '3', '6', 'h', 't', 'm', 'l']
123regular_v9 = re.findall(r"W","https://docs.python.org/3/whatsnew/3.6.html")print (regular_v9)# [':', '/', '/', '.', '.', '/', '/', '/', '.', '.']
这个匹配以#开始,以#结束(不包含#)且包含abc的串
如
target_string="123#83das888abc9999wfsdf#ewrw"
匹配到的结果
['83das888abc9999wfsdf']