我想创建一个regex模式,检查 "jQuery "是否存在于介于 <script>
和 </script>
标签。
例如,我想出了以下的regex
<script>
function foo(jQuery){
alert("i take jQuery in as a parameter!");
}
</script>
我想出了以下的regex。
/(?s)(<script>.*?jQuery.*?<\/script>)/
如果只有一个脚本块,这似乎很好,如果有多个脚本(其中一个包含jQuery),那么regex就会匹配第一个脚本块和第二个脚本块之间的所有内容。 <script>
而最后 </script>
标签。
<script> <-- Match starts
const i = "foo";
</script> <-- no jQuery referenced in this script block...
<p>Hi!</p>
<script>
console.log(jQuery);
</script> <-- Match ends
它应该是这样的
<script> <-- Match starts
console.log(jQuery);
</script> <-- Match ends
<script>
const i = "foo";
</script>
<p>Hi!</p>
<script> <-- Match starts
console.log(jQuery);
</script> <-- Match ends