W3C home > Mailing lists > Public > public-css-archive@w3.org > May 2021

Re: [csswg-drafts] CSS Regex Selector (#1010)

From: Christopher Kirk-Nielsen via GitHub <sysbot+gh@w3.org>
Date: Mon, 17 May 2021 18:22:39 +0000
To: public-css-archive@w3.org
Message-ID: <issue_comment.created-842535686-1621275757-sysbot+gh@w3.org>
Sorry to dig this up, I ran into a need for RegEx on and landed here. Could we imagine perhaps a CSS **attribute** selector that accepts a RegEx, instead of a way to match selectors in general? For example:

[data-filters-sections#="(0|9)+"] {
  opacity: 0.5;

/* I hate this example, too */
.col-wide-sm[class#="col-([0-9]|1[0-2])"] {
  width: 100%;

Two things:
- Not sure which symbol works to best represent "Regular Expression". Personally, I like `#=` but I also recognise the very potential confusion with the CSS ID selector. I could also see `/=` as an alternative but that might have been floated for another type of selector so not too sure. I thought about `?=` and while looks very "RegExy", it feels like an optional attribute selector of sorts to me (optional chaining, non-capturing group, etc.), so not too keen on that one.
- Maybe this should be ignored on `[value]` for security reasons, like we've seen people use `[value$="…"]` to grab data from user input. This might be overzealous as a regular expression won't provide the string (until we have a `regex($1)` function for values, ha) and I've not really run into this issue in the past as I usually have a vanilla approach, but I figured I'd point that out.

Once again, sorry about the old issue revival, just wanted to share the idea, and I'm happy to create a new issue if that makes more sense!

GitHub Notification of comment by chriskirknielsen
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/1010#issuecomment-842535686 using your GitHub account

Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Monday, 17 May 2021 18:22:44 UTC

This archive was generated by hypermail 2.4.0 : Tuesday, 5 July 2022 06:42:33 UTC