如何通过正则表达式删除所有<script> .. </script />之间的内部文本?

时间:2019-06-25 18:37:02

标签: regex

我正在尝试使用正则表达式,以删除两个字符串之间的所有内容...

假设这是我的内容:

    <h2>Misrepresentation of the Facts</h2>
    </script>
    <!-- Articles - Leaderboard 728x90 -->
    </iframe></ins></ins></ins>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>
    <h2>Who Can Commit the Crime</h2>

    I want to remove all content between </script>
    <!-- Articles - Leaderboard 728x90 -->
    </iframe></ins></ins></ins>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>

任何帮助将不胜感激。

<\/script>(?:[^<]*(?!.)+<\/script>

<\/script>(?:[^<]*(?!.)+<\/script>

1 个答案:

答案 0 :(得分:0)

我只是猜测将这些表达式替换为空字符串可能有效:

<\/script>[\s\S]*?<\/script>
<\/script>[\d\D]*?<\/script>
<\/script>[\w\W]*?<\/script>

Please see the demo here

转义仅用于演示,可以将其删除。