不是这样写的要匹配换行的话,加上/s参数然后,如果你用.*匹配<script>到</script>的话,一不小心就把第一个<script>到最后一个</script>中间全删掉了比如说 <script>some script</script>here is the html.not script<script>some script</script>这个时候,里面的HTML也不能幸免。一个简陋的正则是这样: /<script>.*?<\/script>/sg
我不是很赞同。我用/ <script(\\n|\\t|.)*? <\/script>/这个正则“here is the html.not script”不会被删除掉。 因为/ <script(\\n|\\t|.)*? <\/script>/里面包含<\/script>,就是匹配到第一个</script>标签为止,而不会匹配到 后面第二、第三……的</script>标签。 我的说法对吧?!
正则胡写的,不知道行不行。
在<script ......> 后面加个/*
在</script> 前面加个 */
或者把这段JS 注释掉
js code
</script>
这样用正则不能匹配吧?!在我的印象里,正则只能一行一行匹配。不知道有没有理解错?
终于搞定了。
<script>some script</script>here is the html.not script<script>some script</script>这个时候,里面的HTML也不能幸免。一个简陋的正则是这样:
/<script>.*?<\/script>/sg
因为/ <script(\\n|\\t|.)*? <\/script>/里面包含<\/script>,就是匹配到第一个</script>标签为止,而不会匹配到
后面第二、第三……的</script>标签。
我的说法对吧?!