I just had a case where it would have been really useful if there were a CSS selector like :numeral. I could then make all the numerals superscript and change their color.
It then occurred to me that it would be even more useful to have something like :regex('...') which would allow me to use regex to select particular text (numerals preceded by a space, for example: :regex(' \\d*')).
Is there a good reason this sort of selection should not be implemented in CSS Spec?
Yes – performance reasons.
A common request is a “parent selector” (similar to jQuery’s
:has()selector), which is also rejected for similar performance reasons.A good read on this subject is: http://snook.ca/archives/html_and_css/css-parent-selectors
The sheer length of that article is why I’m not attempting to explain this myself.
If a parent selector is too bad from a performance viewpoint, you can imagine that a “regex selector” would be unthinkable.
Especially when you consider that not all regexes are equal: it’s very easy to make very slow regexes.
For example: http://www.regular-expressions.info/catastrophic.html