This RegEx Will Change How You Design With Tailwind

This RegEx Will Change How You Design With Tailwind

Are you using TailwindCSS in you project?

… of course you are it's all the rage lately, and everyone’s using it.

Need to change all the color based utilities in your app because you need to use semantic color names to implement a new color theme, fix dark mode, or change colors for any other reason?

… of course you do! Changes to the user interface, theme and graphics come up all the time.

Have you now realized your styles are dispersed and scattered across all the markup within your project?

… of course you have, and you’ve probably also realized your components aren’t organized as well as you would like.

Well I have a simple regular expression to aid you in swapping out all your old color utilities with new color utilities:


No warranty is provided or inferred. Use at your own peril. Void where prohibited by law. May cause nausea, confusion, or panic. If you experience any of these symptoms, please discontinue use of the regular expression.

The regex above should match against all of the default atomic color utilties that TailwindCSS provides and can be modified to more specifically match your use case. You may want to narrow down the list of color names or utility names to catch a specific subset of utilizations. Custom color names could be added to the list. You might also expand the regex to target specific variant modifiers.

For example, the regular expression below will match instances where at least one of the listed variant modifiers is used; narrows the set of utility names, and matches against a list of custom colors:


List of variant modifiers provided by TailwindCSS


List of default colors


List of utility prefixes


Photo by Darwin Vegher on Unsplash