Remove everything between specific string

前端 未结 2 1863
陌清茗
陌清茗 2021-01-24 06:24

I read a file with javascript and this file contains a lot of begin and end statement like below , and my purpose is to remove every thing that exists between these begin and en

相关标签:
2条回答
  • 2021-01-24 06:54

    To hold text inside the tags:

    var res = string.match(/<BEGIN>([\s\S]*?)<\/END>/g);
    

    To remove text inside the tags:

    var res = string.replace(/([\s\S]*?)<BEGIN>[\s\S]*?<\/END>/g, '$1');
    

    To remove text outside the tags:

    var res = string.replace(/<BEGIN>[\s\S]*?<\/END>/g, '');
    
    0 讨论(0)
  • 2021-01-24 06:54

    Assuming replace is a class you can try this Jquery:

    <script>        
     $( " " ).replaceAll( ".replace" );
     </script>
    
    0 讨论(0)
提交回复
热议问题