正则表达式匹配内联JavaScript

时间:2016-11-21 22:56:12

标签: javascript php regex preg-match

如何提取如下所示的内联javascripts:

<script type="text/javascript">...fetch-me...</script>
<script type="application/javascript">...fetch-me...</script>
<script>...fetch-me...</script>

但要避免匹配非JavaScript和外部资源:

<script type="text/javascript" src="file.js"></script>
<script type="application/javascript" src="file.js"></script>
<script src="file.js"></script>
<script type="application/ld+json">...</script>

这对我来说不起作用:

#<script(?:[^>]*\stype="(?:application|text)/javascript")?[^>]*>(.*?)</script>#isg

https://regex101.com/r/kR1vY6/2

0 个答案:

没有答案