Skip to content Skip to sidebar Skip to footer

Remove Everything Between Specific String

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 end s

Solution 1:

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, '');

Solution 2:

Assuming replace is a class you can try this Jquery:

<script>        
 $( " " ).replaceAll( ".replace" );
 </script>

Post a Comment for "Remove Everything Between Specific String"