W3C home > Mailing lists > Public > www-style@w3.org > July 2011

CSS regexes

From: Joergen W. Lang <joergen_lang@gmx.de>
Date: Wed, 13 Jul 2011 20:00:54 +0200
Message-ID: <4E1DDD56.7030500@gmx.de>
To: www-style@w3.org
Dear CSSWG,

are there any plans to implement one or the other form of regular 
expression in CSS?

I know that attribute selectors do some basic RE matching. But for 
anonymous boxes (a.k.a. plain text) authors are still limited to using 
<span> and friends.

To style the third "word" (combination of 'word' 
characters/syllables/...) in a paragraph one could write:

p::regex(/^(?:\w+\s+){2}(\w+)/) {
   background-color: #cf6;
}

Or maybe she wants to give quotation marks a special treatment:

h1::regex(/['""„“”«»’,]/g) {
   font-family: Baskerville, "Book Antiqua", serif;
   font-style:  italic;
}

After reading the thread regarding the '::first-word pseudo element' [1] 
I can see there are a lot of implications and questions. One argument 
against ::regex() was that it selects actual content.

IMHO it really depends on how authors use regexes. Yes, they could style 
actual content - or they could style things like "every instance of the 
letter 'm'" or "the first instance of the word 'Foobar'" or "the last 
appearance of [almost anything]".

I suppose that most browsers do some sort of pattern matching during the 
parsing process. Maybe an already existing RE engine could be reused for 
this purpose?

Please excuse my intrusion if this has already been discussed and 
decided upon. Hopefully I'm not (re)opening a proverbial Pandora's box here.

Looking forward to your feedback,

Jørgen W. Lang


1) http://lists.w3.org/Archives/Public/www-style/2010Dec/0245.html ff.
Received on Saturday, 16 July 2011 11:33:31 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:42 GMT