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标签中的代码了

文章来自:https://www.cnblogs.com/zhaoyingjie/p/8718963.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3