Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save uluumbch/157d66ec8984f0d41c5b1423ce4fd628 to your computer and use it in GitHub Desktop.
Save uluumbch/157d66ec8984f0d41c5b1423ce4fd628 to your computer and use it in GitHub Desktop.
Delete Tailwind Dark Mode Classes

This guide will show you how to use Visual Studio Code's built-in Find and Replace feature with regular expressions to remove all Tailwind CSS classes prefixed with dark:.

Steps to Delete Dark Mode Classes

  1. Open your project in VS Code.

  2. Open the Find and Replace dialog:

    • Press Ctrl + H (on Windows or Linux).

    • Press Cmd + Option + F (on macOS).

  3. Enable Regular Expressions:

    • In the Find input box that appears, look for an icon that looks like .* on the right side. Click this icon to enable the use of regular expressions. It should become highlighted or change color when active.
  4. Enter the Regular Expression in the "Find" field:

    • In the "Find" input box, paste the following regular expression:

      dark:[a-zA-Z0-9-_:]+
    • Explanation of the Regex:

      • dark:: This part literally matches the string "dark:".

      • [a-zA-Z0-9-_:]: This is a character set that matches any single character that is an uppercase letter (A-Z), a lowercase letter (a-z), a digit (0-9), a hyphen (-), an underscore (_), or a colon (:). These are the characters commonly found in Tailwind class names and their variants (like hover:).

      • +: This quantifier means "match the previous character set one or more times". So, it will match any sequence of the allowed characters that follows dark:.

  5. Leave the "Replace" field empty:

    • Ensure the "Replace" input box is completely empty. This tells VS Code to replace whatever is found by the regex with nothing, effectively deleting it.
  6. Perform the Replacement:

    • To replace in the current file only:

      • Click the "Replace All" icon next to the "Replace" input box. This icon typically looks like two overlapping squares.
    • To replace across multiple files in your project:

      • Close the Find and Replace dialog in the editor by pressing Escape.

      • Open the Search view by pressing Ctrl + Shift + F (Windows/Linux) or Cmd + Shift + F (macOS).

      • In the search box at the top of the Search view, paste the same regex: dark:[a-zA-Z0-9-_:]+.

      • Make sure the "Use Regular Expression" icon (.*) below the search box is enabled.

      • Expand the search options if necessary (click the arrow or ellipsis icon).

      • An "Replace" input box will appear below the search box. Leave this box empty.

      • You can use the "files to include" and "files to exclude" fields to refine which files are searched if needed.

      • Click the "Replace All" icon (the two overlapping squares) in the Search view.

Important Tips

  • Test Thoroughly: Before clicking "Replace All," use the Find feature (or the search results in the Search view) to review all the matches. Make sure the regex is only selecting the dark: classes you want to remove and not accidentally matching other text.

  • Use Version Control: It is highly recommended to have your project under version control (like Git) or to make a backup copy of your files before performing a large-scale find and replace operation. This allows you to easily revert the changes if anything goes wrong.

Following these steps will help you quickly remove the specified Tailwind CSS dark mode classes from your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment