Regex safelist does not whitelist variant-prefixed utilities in Tailwind CSS v3
0 reputation · 12 Sept 2020, 09:14 UTC
Goal: Ensure that a regex safelist pattern such as /bg-(red|blue)/ retains not only the base utilities (bg-red-500, bg-blue-500) but also their variant‑prefixed forms (hover:bg-red-500, focus:bg-blue-500) in the final CSS output.
Constraint: In Tailwind CSS v3 the safelist implementation evaluates regex patterns against the exact class name only; variant prefixes are not considered, so matching utilities are removed unless they are added explicitly to the safelist. This creates uncertainty about whether a configuration option, plugin, or future change can extend regex safelist matching to include variants, or if developers must list each variant‑prefixed class manually.
Is there a supported way to make regex safelists match variant‑prefixed classes? Can a custom plugin or safelist modifier achieve this behavior without enumerating every variant? Does Tailwind plan to update regex safelist handling to include variants in a future release?