python匹配两个字符串中间的字符串 - 星河赵

时间:2024-02-19 09:17:43

python匹配两个字符串中间的字符串

问题:使用python正则如何匹配两字符串中间的字符串
解决:使用re模块的findall,注意,re.match是只能从开头匹配的
方法:

import re
html_str = \'</a></div></div><script>var Locafds fds fds fds fds fds fds ;</script></body></html>\'
local = re.findall(r\'</div><script>(.*)</script></body>\', html_str)
print(local[0])
#\'var Locafds fds fds fds fds fds fds ;\'

 



这样就可以匹配到script标签中的代码了