Home > OS >  How would I replace all underscores in HTML tag IDs & classes with a hyphen?
How would I replace all underscores in HTML tag IDs & classes with a hyphen?

Time:11-10

I have written some bad CSS class & id names with underscores instead of hyphens. I’m trying to change all underscores to hyphens with sublime text replace feature (ctrl H). How would I change underscores to hyphens in my HTML template only for id and class names?

From this:

<div id=“contact_container”></div>

To this:

<div id="contact-container"></div>

CodePudding user response:

You can utilize Regex in your search. Regex is a way to create "rules" for the search. You'll be able to tell the search, "find everything that starts with 'id=' and has a '-' in it," for example.

Since I don't know how the rest of your code looks I can't tell you exactly what your Regex expression should be but this article on using Regex in Sublime might be a helpful starting point.

  • Related