CSS: regular expressions in selectors

Among the various proposals for CSS extensions suggested to the W3C CSS Working Group there is the use of regular expressions in selectors. This feature is rather interesting because it would allow developers to select elements and attributes in a more powerful way. For example, H<[0-9]+]> matches all names H0, H1,... H10, H11, H12,... etc. If this feature will be supported in the future, we could write complex patterns to select elements based on the returned matches.

It's not clear what flavor of regular expressions would be supported by browsers. Browsers that support HTML5 forms already feature an implementation of regular expression while validating form fields, such as <input type="email" />, but the main obstacle to an actual adoption of regular expressions in CSS selectors remain the complexity of patterns. Since CSS is simple by design, using regular expressions would surely increase the level of complexity and the difficulty related to a proper understanding and use of this standard.

This entry was posted in by Gabriele Romanato. Bookmark the permalink.

Leave a Reply

Note: Only a member of this blog may post a comment.