4

I'm trying to figure out the correct regex expression for the selector-class-pattern's I want to allow with stylelint

https://stylelint.io/user-guide/rules/selector-class-pattern/

I would only like to allow lowercase letters and numbers seperated by hyphons, and only allow underscores at the beginning. So basically the following

.this-is-good
.also-good2
._this-works-too

.-not-this
.or-this-
.and_not_this
.OR-This

I've almost gotten it to work but can't get it to allow underscores only at the beginning of the pattern.

"selector-class-pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
Holly
  • 7,462
  • 23
  • 86
  • 140

1 Answers1

1

Stylelint demo page with exactly the rule that works for you:

"selector-class-pattern": "selector-class-pattern": "^([_a-z][a-z0-9]*)(-[a-z0-9]+)*$",

enter image description here

vsync
  • 118,978
  • 58
  • 307
  • 400