Match everything in between two strings using sublime text

Often when working on projects with multiple files,

we may need to find everything in between two strings and replace them.

 

example:

moving all global js files (files which will be used in all files) within comments like

<!-- global js -->
<script src="js/jquery-1.11.1.min.js"></script>
<!-- Bootstrap -->
<script src="js/bootstrap.min.js"></script>
<!-- end of global js -->

when we finish up a project, we realize we need to add some more into global js section and easiest way to do that in all files using sublime is,

press ctrl+shift+p to open find in files
press alt + R to enable regular expressions

then search for

<!-- global js -->(?s)(.*)<!-- end of global js -->

If you want to find multiple occurrences of that string, searach for

<!-- global js -->(?s:)(.*)<!-- end of global js -->

Now it will find out in pages where something exists in between global js comments and you can do any kind of modifications you want with ‘Replace’ option in sublime

Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.