regex - Find and replace between html comment tags in dreamweaver -


i'm trying dreamweaver remove content between 2 html comment tags. have lot of html pages in project have bunch of js scripts in bottom , different page page.

for example, let's have following html:

  <!-- scripts -->   <script src="http://code.jquery.com/jquery-latest.js"></script>   <script src="assets/js/custom.js"></script>   <!-- end scripts --> 

and i'd find , replace strips between comment tags , replaces new stuff:

  <!-- scripts -->   <script src="new-path-for-js-files.js"></script>   <!-- end scripts --> 

i believe possible achieve using regex couldn't find fit i'm looking for.

i'd appreciate suggestions on accomplishing this.

many thanks!

you can match comment tags including content surround using following regex:

<!-- scripts -->[\s\s]*?<!-- end scripts --> 

explanation:
regex looks exact text <!-- scripts --> , <!-- end scripts -->, , tries match characters in between:

  • \s whitespace character class (containing whitespace character spaces, tabs, line breaks);
  • \s try match not in whitespace character class
  • [\s\s] character set, tries mach character contains, in case means character;
  • * quantifier tries match 0 or more of preceding token [\s\s]
  • ? modifier makes preceding quantifier lazy: default quantifier * greedy , tries match many characters possible, lazy modifier changes quantifier tries match few characters possible. necessary if have multiple identical tags.

you said want replace code inside tags (so keeping tags), suggested regex not (it match - , replace - comment tags). possible regex using lookarounds, make regex more difficult; , part of regex flavors (partially) support lookarounds.
suggest add comment tags around replacement code if want keep them in source code.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -