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

时间:2018-04-04 23:24:10   收藏:0   阅读:3167

问题:使用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标签中的代码了

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!