Skip to content

Instantly share code, notes, and snippets.

@Potherca

Potherca/README.md

Last active Nov 4, 2020
Embed
What would you like to do?
The search for a Regex to match BEM CSS class-names

The search for a Regex to match BEM CSS class-names

TL;DR

Use this regular expression to match BEM class-names:

^\.[a-z]([a-z0-9-]+)?(__([a-z0-9]+-?)+)?(--([a-z0-9]+-?)+){0,2}$

Usage

This repository contains code that makes it easy to test regular expressions that shoud match all valid BEM class-names.

Just run index.php and edit the test.pass, test.fail or BEM.regex files:

  • test.pass All class names that a BEM regex SHOULD match
  • test.fail All class names that a BEM regex SHOULD NOT match
  • BEM.regex Regular expression(s) to test.

In both the test.pass, test.fail and files, only lines that start with a dot . character are used.

In the BEM.regex file, only lines that start with a caret ^ are used.

The easiest way to run the index.php is to use PHP's built-in web server:

php -S localhost:8080

If improvements are found, the BEM regex in version2 needs to be updated.

It is located in the .sasslintrc file in the root of the project.

The full story

Using Hyphenated BEM

As part of an initiative to use a more standardised approach to writing CSS, at my current employers, we are using BEM to define class names for one of the projects I am involved in.

BEM stands for Block Element Modifier. It is a methodology invented at Yandex to create extendable and reusable interface components.

There are two naming conventions in BEM that are most popular:

  • Classic style (also known as "Strict BEM").
  • Two Dashes style (also known as "Hyphenated BEM").

Both have similarities:

  • Names are written in lowercase Latin letters.
  • Words within the names of BEM entities are separated by a hyphen (-).
  • The element name is separated from the block name by a double underscore (__).
  • For boolean modifiers, the value is not included in the name.

The major difference between the two is the fact that a modifier name (or value) is separated from its sibling by a single underscore _ in Strict BEM and by a double hyphen -- in Hyphenated BEM (hence the name).

Because we find it more readable, we use Hyphenated BEM.

Custom Sass Lint class name format

In order to make sure everybody adheres to this convention, we use sass-lint. Sass-lint comes with support for both Strict BEM and Hyphenated BEM for class-names, straight out of the box.

But as we are in the process of moving from one convention to another, we wanted to be able to support two conventions, side-by-side.

For sass-lint, this means setting up a custom regular expression (or "regex") for the class-name-format rule.

And so the search began to create a (re)usable regex.

Creating use-cases

Before starting the search, we created a test-case that outlined what should and should not be matched.

The BEM entities that are available are:

  • Block (.block-name)
  • Element (__element-name)
  • Modifier Name (--modifier-name)
  • Modifier Value (--modifier-value)

Together this gives us a maximum combination of:

.block-name__element-name--modifier-name--modifier-value

As we are using Hyphenated BEM style, we want a regex that matches that. We don't really care for (also) being able to match the Classic style.

Valid combinations

This gives us the following valid combinations:

  • Block Only
  • Block + Element
  • Block + Modifier
  • Block + Modifier Name + Modifier Value
  • Block + Element + Modifier
  • Block + Element + Modifier Name + Modifier Value

With multiple words within each entity separated by a hyphen -. We need to take into account that single letter names are valid, even if they are undesirable.

This gives us roughly 84 variations that are valid Hyphenated BEM class names.

(For full result see appendix A test.pass).

Invalid combinations

Combinations that are not valid are:

  • Classes with underscores
  • Mixing dashes and underscores
  • Multiple similar BEM item (meaning more than one Element or more than two Modifiers)
  • Trailing dashes
  • Trailing underscores
  • Wrong order (Modifier before Element)
  • Mixed dash and underscore in BEM separator (the separator should only be -- or __)

Multiple words within each entity separated with something other than hyphen -.

Combining all of these with various edge-cases brings the amount of combinations to nearly 450.

(For full result see appendix B test.fail).

Finding a Regular Expression

Armed with almost 500 lines to match against, we feel we have a fairly complete dataset to set out with.

Being lazy, instead of creating a regex ourselves, we first looked for an existing regex. There did not seem to be much out there...

First miss

In the Validating BEM using regex blog-post, Samir Alajmovic made the following suggestion for matching BEM class-names:

^\.((([a-z0-9]+(_[a-z0-9]+)?)+((--)([a-z0-9]+(-[a-z0-9]+)?)+)?)|(([a-z0-9]+(_[a-z0-9]+)?)+__([a-z0-9]+(_[a-z0-9]+)?)+((--)([a-z0-9]+(-[a-z0-9]+)?)+)?))$

However, this seemed to be geared more toward Classic BEM, as words within each entity need to be separated by an underscore _. It also does not take modifier values into account.

Of course, we can rework the regex to a working version.

This requires adding support for modifier values, forcing the first character to be letter, and fixing one missing use-case.

That gives us:

^\.((([a-z](-[a-z0-9]+)*)+((--)([a-z0-9]+(-[a-z0-9]+)?)+){0,2})|(([a-z](-[a-z0-9]+)?)+__([a-z0-9]+(-[a-z0-9]+)?)+((--)([a-z0-9]+(-[a-z0-9]+)?)+){0,2}))$

This can be reworked further to reduce some duplication and remove redundant capture groups.

^\.([a-z](-[a-z0-9]+)*)+(__[a-z0-9]+(-[a-z0-9]+)?)?(--[a-z0-9]+(-[a-z0-9]+)?){0,2}$

First hit

In a comment, in a ticket in the postcss-bem-linter repository Corey Bruyere suggests a regex.

^\.[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*(?:__[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*)?(?:--[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*)?$

It also doesn't take modifier values into account, but that is easy enough to remedy. Again, we need to force the first character to be a letter. Finally, we can move the case-sensitive A-Z to outside the regex, as case-sensitivity can be set by a flag in whatever tool runs the regex.

That gives us:

^\.[a-z]+(?:-[a-z0-9]+)*(?:__[a-z0-9]+(?:-[a-z0-9]+)*)?(?:--[a-z0-9]+(?:-[a-z0-9]+)*){0,2}$

This can also be reduced further by removing redundant (non)capturing groups:

^\.[a-z]+(-[a-z0-9]+)*(__[a-z0-9]+(-[a-z0-9]+)*)?(--[a-z0-9]+(-[a-z0-9]+)*){0,2}$

Batter up!

The cleaned-up regular expressions both still look somewhat verbose...

^\.([a-z](-[a-z0-9]+)*)+(__[a-z0-9]+(-[a-z0-9]+)?)?(--[a-z0-9]+(-[a-z0-9]+)?){0,2}$
^\.[a-z]+(-[a-z0-9]+)*(__[a-z0-9]+(-[a-z0-9]+)*)?(--[a-z0-9]+(-[a-z0-9]+)*){0,2}$

The next step is to improve upon these regular expressions. What do we need to keep, what can be removed and what can be cleaned up?

Keep

We'll need to keep that [a-z] at the start, as class-names must start with a letter. The {0,2}$ at the end will also be needed to allow for modifier values.

Remove

Both regex use the sequence -[a-z0-9]+ four times. I get the feeling that could be less.

Both regex also uses repetition operators (or quantifier) ten times. (The question mark ?, plus sign +, and star character (or asterisk) *).

I'm not sure this number can be brought down, but I would like to try.

Clean up

I dislike the use of the star quantifier *. If possible I would opt not to use it.

Home run!

Keeping the concerns stated above in my mind, I got to work.

The end result is this:

^\.[a-z]([a-z0-9-]+)?(__([a-z0-9]+-?)+)?(--([a-z0-9]+-?)+){0,2}$

It is seventeen (or nineteen) characters short than both cleaned-up regular expressions. That's more than half shorter than the original non-cleaned-up versions.

Besides that, it looks a lot more readable to me.

So, what do you think? Better?

If you like it, feel free to use it. If not, don't hesitate to leave a comment!

This file contains variations of regular expressions that are tested by the PHP file.
Only lines that start with a caret `^` character are tested. All other lines are ignored.
/* Based on Samir Alajmovic's work */
^\.([a-z](-[a-z0-9]+)*)+(__[a-z0-9]+(-[a-z0-9]+)?)?(--[a-z0-9]+(-[a-z0-9]+)?){0,2}$
/* Based on Corey Bruyere's work */
^\.[a-z]+(-[a-z0-9]+)*(__[a-z0-9]+(-[a-z0-9]+)*)?(--[a-z0-9]+(-[a-z0-9]+)*){0,2}$
/* Our attempt */
^\.[a-z]([a-z0-9-]+)?(__([a-z0-9]+-?)+)?(--([a-z0-9]+-?)+){0,2}$
<!doctype html>
<?php
function get_subjects($subjects) {
return array_map('trim', array_filter($subjects, function ($line) {
return trim($line) !== '' && $line{0} === '.';
}));
}
$fullPassingMatches = file(__DIR__ . '/test.pass');
$fullFailingMatches = file(__DIR__ . '/test.fail');
$passingMatches = get_subjects($fullPassingMatches);
$failingMatches = get_subjects($fullFailingMatches);
$fullSubjects = implode("\n", array_merge($fullPassingMatches, $fullFailingMatches));
$subjects = implode("\n", array_merge($passingMatches, $failingMatches));
$regexs = file(__DIR__ . '/BEM.regex');
$regexs = array_filter($regexs, function ($pattern) {
return trim($pattern) !== '' && $pattern{0} === '^';
});
$result = '';
array_walk($regexs, function ($regex) use (&$result, $passingMatches, $subjects) {
$regex = trim($regex);
$pattern = vsprintf("/%s/m", [$regex]);
$encodedPattern = htmlentities($regex);
$match = preg_match_all($pattern, $subjects, $matches);
// @TODO: Mark test as error if $match === false
$shouldMatch = array_diff($passingMatches, $matches[0]);
$shouldNotMatch = array_diff($matches[0], $passingMatches);
if ($shouldMatch === [] && $shouldNotMatch === []) {
$result .= '<p><span class="pass">Success.</span> <code>' . $encodedPattern .'</code></p>';
} else {
$result .= '<p><span class="fail">Failure.</span> <code>' . $encodedPattern .'</code></p>';
$glue = '</code></li><li><code>';
if ($shouldMatch !== []) {
$result .= '<p>The following items SHOULD have been matched but were not:</p>'
. '<ul><li><code>'.join($glue, $shouldMatch).'</code></li></ul>'
;
}
if ($shouldNotMatch !== []) {
$result .= '<p>The following items SHOULD NOT have been matched but were:</p>'
. '<ul><li><code>'.join($glue, $shouldNotMatch).'</code></li></ul>'
;
}
}
});
?>
<html lang="en">
<head>
<title></title>
<style>
summary {
border: 1px solid #CCC;
cursor: pointer;
display: inline;
padding: 0.2em;
}
.fail {
background-color: red;
color: white;
display: inline;
padding: 0.2em;
}
.pass {
background-color: limegreen;
color: white;
display: inline;
padding: 0.2em;
}
</style>
</head>
<body>
<h1>Regex for BEM</h1>
<h2>The regular expressions</h2>
<?= $result; ?>
<h2>The text matched against</h2>
<details>
<summary>Click to open</summary>
<pre><code><?= $fullSubjects; ?></code></pre>
</details>
</body>
</html>
/* ****************************************************************************\
|* These SHOULD NOT be matched *|
\******************************************************************************/
/* Invalid class names , cannot start with a digit, two hyphens, or a hyphen followed by a digit. */
.0ne
.-0ne
.--one
/* Classes with underscore */
.one_two
.one_two_three
.one_two_three_in_fi_ni_ty
/* Mixed dash and underscore */
.one-two_three
.one_two-three
/* Double BEM item */
.block__element__element
.block__element__element--modifier
.block__element__element--modifier--modifier
.block__element--modifier--modifier--modifier
.block__element__element--modifier--modifier--modifier
/* Leading dash */
.-block
.-other-block
.-block__element
.-other-block__element
.-block__other-element
.-other-block__other-element
.-block--modifier
.-other-block--modifier
.-block--other-modifier
.-other-block--other-modifier
.-block--modifier--value
.-block--modifier--other-value
.-other-block--modifier--value
.-other-block--modifier--other-value
.-block--other-modifier--value
.-block--other-modifier--other-value
.-other-block--other-modifier--value
.-other-block--other-modifier--other-value
.-block__element--modifier
.-block__element--other-modifier
.-block__other-element--modifier
.-block__other-element--other-modifier
.-other-block__element--modifier
.-other-block__element--other-modifier
.-other-block__other-element--modifier
.-other-block__other-element--other-modifier
.-block__element--modifier--value
.-block__element--modifier--other-value
.-block__element--other-modifier--value
.-block__element--other-modifier--other-value
.-block__other-element--modifier--value
.-block__other-element--modifier--other-value
.-block__other-element--other-modifier--value
.-block__other-element--other-modifier--other-value
.-other-block__element--modifier--value
.-other-block__element--modifier--other-value
.-other-block__element--other-modifier--value
.-other-block__element--other-modifier--other-value
.-other-block__other-element--modifier--value
.-other-block__other-element--modifier--other-value
.-other-block__other-element--other-modifier--value
.-other-block__other-element--other-modifier--other-value
/* Leading double dash */
.--block
.--other-block
.--block__element
.--other-block__element
.--block__other-element
.--other-block__other-element
.--block--modifier
.--other-block--modifier
.--block--other-modifier
.--other-block--other-modifier
.--block--modifier--value
.--block--modifier--other-value
.--other-block--modifier--value
.--other-block--modifier--other-value
.--block--other-modifier--value
.--block--other-modifier--other-value
.--other-block--other-modifier--value
.--other-block--other-modifier--other-value
.--block__element--modifier
.--block__element--other-modifier
.--block__other-element--modifier
.--block__other-element--other-modifier
.--other-block__element--modifier
.--other-block__element--other-modifier
.--other-block__other-element--modifier
.--other-block__other-element--other-modifier
.--block__element--modifier--value
.--block__element--modifier--other-value
.--block__element--other-modifier--value
.--block__element--other-modifier--other-value
.--block__other-element--modifier--value
.--block__other-element--modifier--other-value
.--block__other-element--other-modifier--value
.--block__other-element--other-modifier--other-value
.--other-block__element--modifier--value
.--other-block__element--modifier--other-value
.--other-block__element--other-modifier--value
.--other-block__element--other-modifier--other-value
.--other-block__other-element--modifier--value
.--other-block__other-element--modifier--other-value
.--other-block__other-element--other-modifier--value
.--other-block__other-element--other-modifier--other-value
/* Trailing dash */
.block-
.other-block-
.block__element-
.other-block__element-
.block__other-element-
.other-block__other-element-
.block--modifier-
.other-block--modifier-
.block--other-modifier-
.other-block--other-modifier-
.block--modifier--value-
.block--modifier--other-value-
.other-block--modifier--value-
.other-block--modifier--other-value-
.block--other-modifier--value-
.block--other-modifier--other-value-
.other-block--other-modifier--value-
.other-block--other-modifier--other-value-
.block__element--modifier-
.block__element--other-modifier-
.block__other-element--modifier-
.block__other-element--other-modifier-
.other-block__element--modifier-
.other-block__element--other-modifier-
.other-block__other-element--modifier-
.other-block__other-element--other-modifier-
.block__element--modifier--value-
.block__element--modifier--other-value-
.block__element--other-modifier--value-
.block__element--other-modifier--other-value-
.block__other-element--modifier--value-
.block__other-element--modifier--other-value-
.block__other-element--other-modifier--value-
.block__other-element--other-modifier--other-value-
.other-block__element--modifier--value-
.other-block__element--modifier--other-value-
.other-block__element--other-modifier--value-
.other-block__element--other-modifier--other-value-
.other-block__other-element--modifier--value-
.other-block__other-element--modifier--other-value-
.other-block__other-element--other-modifier--value-
.other-block__other-element--other-modifier--other-value-
/* Trailing double dash */
.block--
.other-block--
.block__element--
.other-block__element--
.block__other-element--
.other-block__other-element--
.block--modifier--
.other-block--modifier--
.block--other-modifier--
.other-block--other-modifier--
.block--modifier--value--
.block--modifier--other-value--
.other-block--modifier--value--
.other-block--modifier--other-value--
.block--other-modifier--value--
.block--other-modifier--other-value--
.other-block--other-modifier--value--
.other-block--other-modifier--other-value--
.block__element--modifier--
.block__element--other-modifier--
.block__other-element--modifier--
.block__other-element--other-modifier--
.other-block__element--modifier--
.other-block__element--other-modifier--
.other-block__other-element--modifier--
.other-block__other-element--other-modifier--
.block__element--modifier--value--
.block__element--modifier--other-value--
.block__element--other-modifier--value--
.block__element--other-modifier--other-value--
.block__other-element--modifier--value--
.block__other-element--modifier--other-value--
.block__other-element--other-modifier--value--
.block__other-element--other-modifier--other-value--
.other-block__element--modifier--value--
.other-block__element--modifier--other-value--
.other-block__element--other-modifier--value--
.other-block__element--other-modifier--other-value--
.other-block__other-element--modifier--value--
.other-block__other-element--modifier--other-value--
.other-block__other-element--other-modifier--value--
.other-block__other-element--other-modifier--other-value--
/* Leading underscore */
._block
._other-block
._block__element
._other-block__element
._block__other-element
._other-block__other-element
._block--modifier
._other-block--modifier
._block--other-modifier
._other-block--other-modifier
._block--modifier--value
._block--modifier--other-value
._other-block--modifier--value
._other-block--modifier--other-value
._block--other-modifier--value
._block--other-modifier--other-value
._other-block--other-modifier--value
._other-block--other-modifier--other-value
._block__element--modifier
._block__element--other-modifier
._block__other-element--modifier
._block__other-element--other-modifier
._other-block__element--modifier
._other-block__element--other-modifier
._other-block__other-element--modifier
._other-block__other-element--other-modifier
._block__element--modifier--value
._block__element--modifier--other-value
._block__element--other-modifier--value
._block__element--other-modifier--other-value
._block__other-element--modifier--value
._block__other-element--modifier--other-value
._block__other-element--other-modifier--value
._block__other-element--other-modifier--other-value
._other-block__element--modifier--value
._other-block__element--modifier--other-value
._other-block__element--other-modifier--value
._other-block__element--other-modifier--other-value
._other-block__other-element--modifier--value
._other-block__other-element--modifier--other-value
._other-block__other-element--other-modifier--value
._other-block__other-element--other-modifier--other-value
/* Leading double underscore */
.__block
.__other-block
.__block__element
.__other-block__element
.__block__other-element
.__other-block__other-element
.__block--modifier
.__other-block--modifier
.__block--other-modifier
.__other-block--other-modifier
.__block--modifier--value
.__block--modifier--other-value
.__other-block--modifier--value
.__other-block--modifier--other-value
.__block--other-modifier--value
.__block--other-modifier--other-value
.__other-block--other-modifier--value
.__other-block--other-modifier--other-value
.__block__element--modifier
.__block__element--other-modifier
.__block__other-element--modifier
.__block__other-element--other-modifier
.__other-block__element--modifier
.__other-block__element--other-modifier
.__other-block__other-element--modifier
.__other-block__other-element--other-modifier
.__block__element--modifier--value
.__block__element--modifier--other-value
.__block__element--other-modifier--value
.__block__element--other-modifier--other-value
.__block__other-element--modifier--value
.__block__other-element--modifier--other-value
.__block__other-element--other-modifier--value
.__block__other-element--other-modifier--other-value
.__other-block__element--modifier--value
.__other-block__element--modifier--other-value
.__other-block__element--other-modifier--value
.__other-block__element--other-modifier--other-value
.__other-block__other-element--modifier--value
.__other-block__other-element--modifier--other-value
.__other-block__other-element--other-modifier--value
.__other-block__other-element--other-modifier--other-value
/* Trailing underscore */
.block_
.other-block_
.block__element_
.other-block__element_
.block__other-element_
.other-block__other-element_
.block--modifier_
.other-block--modifier_
.block--other-modifier_
.other-block--other-modifier_
.block--modifier--value_
.block--modifier--other-value_
.other-block--modifier--value_
.other-block--modifier--other-value_
.block--other-modifier--value_
.block--other-modifier--other-value_
.other-block--other-modifier--value_
.other-block--other-modifier--other-value_
.block__element--modifier_
.block__element--other-modifier_
.block__other-element--modifier_
.block__other-element--other-modifier_
.other-block__element--modifier_
.other-block__element--other-modifier_
.other-block__other-element--modifier_
.other-block__other-element--other-modifier_
.block__element--modifier--value_
.block__element--modifier--other-value_
.block__element--other-modifier--value_
.block__element--other-modifier--other-value_
.block__other-element--modifier--value_
.block__other-element--modifier--other-value_
.block__other-element--other-modifier--value_
.block__other-element--other-modifier--other-value_
.other-block__element--modifier--value_
.other-block__element--modifier--other-value_
.other-block__element--other-modifier--value_
.other-block__element--other-modifier--other-value_
.other-block__other-element--modifier--value_
.other-block__other-element--modifier--other-value_
.other-block__other-element--other-modifier--value_
.other-block__other-element--other-modifier--other-value_
/* Trailing double underscore */
.block__
.other-block__
.block__element__
.other-block__element__
.block__other-element__
.other-block__other-element__
.block--modifier__
.other-block--modifier__
.block--other-modifier__
.other-block--other-modifier__
.block--modifier--value__
.block--modifier--other-value__
.other-block--modifier--value__
.other-block--modifier--other-value__
.block--other-modifier--value__
.block--other-modifier--other-value__
.other-block--other-modifier--value__
.other-block--other-modifier--other-value__
.block__element--modifier__
.block__element--other-modifier__
.block__other-element--modifier__
.block__other-element--other-modifier__
.other-block__element--modifier__
.other-block__element--other-modifier__
.other-block__other-element--modifier__
.other-block__other-element--other-modifier__
.block__element--modifier--value__
.block__element--modifier--other-value__
.block__element--other-modifier--value__
.block__element--other-modifier--other-value__
.block__other-element--modifier--value__
.block__other-element--modifier--other-value__
.block__other-element--other-modifier--value__
.block__other-element--other-modifier--other-value__
.other-block__element--modifier--value__
.other-block__element--modifier--other-value__
.other-block__element--other-modifier--value__
.other-block__element--other-modifier--other-value__
.other-block__other-element--modifier--value__
.other-block__other-element--modifier--other-value__
.other-block__other-element--other-modifier--value__
.other-block__other-element--other-modifier--other-value__
/* Wrong order */
.block--modifier__element
.block--modifier--modifier__element
/* Mixed dash and underscore in BEM separator */
.block-__element
.other-block-__element
.block-__other-element
.other-block-__other-element
.block-__element--modifier
.block-__element--other-modifier
.block-__other-element--modifier
.block-__other-element--other-modifier
.other-block-__element--modifier
.other-block-__element--other-modifier
.other-block-__other-element--modifier
.other-block-__other-element--other-modifier
.block-__element--modifier--value
.block-__element--modifier--other-value
.block-__element--other-modifier--value
.block-__element--other-modifier--other-value
.block-__other-element--modifier--value
.block-__other-element--modifier--other-value
.block-__other-element--other-modifier--value
.block-__other-element--other-modifier--other-value
.other-block-__element--modifier--value
.other-block-__element--modifier--other-value
.other-block-__element--other-modifier--value
.other-block-__element--other-modifier--other-value
.other-block-__other-element--modifier--value
.other-block-__other-element--modifier--other-value
.other-block-__other-element--other-modifier--value
.other-block-__other-element--other-modifier--other-value
.block_-_element
.other-block_-_element
.block_-_other-element
.other-block_-_other-element
.block_-_element--modifier
.block_-_element--other-modifier
.block_-_other-element--modifier
.block_-_other-element--other-modifier
.other-block_-_element--modifier
.other-block_-_element--other-modifier
.other-block_-_other-element--modifier
.other-block_-_other-element--other-modifier
.block_-_element--modifier--value
.block_-_element--modifier--other-value
.block_-_element--other-modifier--value
.block_-_element--other-modifier--other-value
.block_-_other-element--modifier--value
.block_-_other-element--modifier--other-value
.block_-_other-element--other-modifier--value
.block_-_other-element--other-modifier--other-value
.other-block_-_element--modifier--value
.other-block_-_element--modifier--other-value
.other-block_-_element--other-modifier--value
.other-block_-_element--other-modifier--other-value
.other-block_-_other-element--modifier--value
.other-block_-_other-element--modifier--other-value
.other-block_-_other-element--other-modifier--value
.other-block_-_other-element--other-modifier--other-value
.block__-element
.other-block__-element
.block__-other-element
.other-block__-other-element
.block__-element--modifier
.block__-element--other-modifier
.block__-other-element--modifier
.block__-other-element--other-modifier
.other-block__-element--modifier
.other-block__-element--other-modifier
.other-block__-other-element--modifier
.other-block__-other-element--other-modifier
.block__-element--modifier--value
.block__-element--modifier--other-value
.block__-element--other-modifier--value
.block__-element--other-modifier--other-value
.block__-other-element--modifier--value
.block__-other-element--modifier--other-value
.block__-other-element--other-modifier--value
.block__-other-element--other-modifier--other-value
.other-block__-element--modifier--value
.other-block__-element--modifier--other-value
.other-block__-element--other-modifier--value
.other-block__-element--other-modifier--other-value
.other-block__-other-element--modifier--value
.other-block__-other-element--modifier--other-value
.other-block__-other-element--other-modifier--value
.other-block__-other-element--other-modifier--other-value
.block_--modifier
.other-block_--modifier
.block_--other-modifier
.other-block_--other-modifier
.block_--modifier_--value
.block_--modifier_--other-value
.other-block_--modifier--value
.other-block--modifier_--value
.other-block_--modifier_--value
.other-block_--modifier--other-value
.other-block--modifier_--other-value
.other-block_--modifier_--other-value
.block_--other-modifier--value
.block--other-modifier_--value
.block_--other-modifier_--value
.block_--other-modifier--other-value
.block--other-modifier_--other-value
.block_--other-modifier_--other-value
.other-block_--other-modifier--value
.other-block--other-modifier_--value
.other-block_--other-modifier_--value
.other-block_--other-modifier--other-value
.other-block--other-modifier_--other-value
.other-block_--other-modifier_--other-value
.block__element_--modifier
.block__element_--other-modifier
.block__other-element_--modifier
.block__other-element_--other-modifier
.other-block__element_--modifier
.other-block__element_--other-modifier
.other-block__other-element_--modifier
.other-block__other-element_--other-modifier
.block__element_--modifier--value
.block__element--modifier_--value
.block__element_--modifier_--value
.block__element_--modifier--other-value
.block__element--modifier_--other-value
.block__element_--modifier_--other-value
.block__element_--other-modifier--value
.block__element--other-modifier_--value
.block__element_--other-modifier_--value
.block__element_--other-modifier--other-value
.block__element--other-modifier_--other-value
.block__element_--other-modifier_--other-value
.block__other-element_--modifier--value
.block__other-element--modifier_--value
.block__other-element_--modifier_--value
.block__other-element_--modifier--other-value
.block__other-element--modifier_--other-value
.block__other-element_--modifier_--other-value
.block__other-element_--other-modifier--value
.block__other-element--other-modifier_--value
.block__other-element_--other-modifier_--value
.block__other-element_--other-modifier--other-value
.block__other-element--other-modifier_--other-value
.block__other-element_--other-modifier_--other-value
.other-block__element_--modifier--value
.other-block__element--modifier_--value
.other-block__element_--modifier_--value
.other-block__element_--modifier--other-value
.other-block__element--modifier_--other-value
.other-block__element_--modifier_--other-value
.other-block__element_--other-modifier--value
.other-block__element--other-modifier_--value
.other-block__element_--other-modifier_--value
.other-block__element_--other-modifier--other-value
.other-block__element--other-modifier_--other-value
.other-block__element_--other-modifier_--other-value
.other-block__other-element_--modifier--value
.other-block__other-element--modifier_--value
.other-block__other-element_--modifier_--value
.other-block__other-element_--modifier--other-value
.other-block__other-element--modifier_--other-value
.other-block__other-element_--modifier_--other-value
.other-block__other-element_--other-modifier--value
.other-block__other-element--other-modifier_--value
.other-block__other-element_--other-modifier_--value
.other-block__other-element_--other-modifier--other-value
.other-block__other-element--other-modifier_--other-value
.other-block__other-element_--other-modifier_--other-value
.block-_-modifier
.other-block-_-modifier
.block-_-other-modifier
.other-block-_-other-modifier
.block-_-modifier-_-value
.block-_-modifier-_-other-value
.other-block-_-modifier--value
.other-block--modifier-_-value
.other-block-_-modifier-_-value
.other-block-_-modifier--other-value
.other-block--modifier-_-other-value
.other-block-_-modifier-_-other-value
.block-_-other-modifier--value
.block--other-modifier-_-value
.block-_-other-modifier-_-value
.block-_-other-modifier--other-value
.block--other-modifier-_-other-value
.block-_-other-modifier-_-other-value
.other-block-_-other-modifier--value
.other-block--other-modifier-_-value
.other-block-_-other-modifier-_-value
.other-block-_-other-modifier--other-value
.other-block--other-modifier-_-other-value
.other-block-_-other-modifier-_-other-value
.block__element-_-modifier
.block__element-_-other-modifier
.block__other-element-_-modifier
.block__other-element-_-other-modifier
.other-block__element-_-modifier
.other-block__element-_-other-modifier
.other-block__other-element-_-modifier
.other-block__other-element-_-other-modifier
.block__element-_-modifier--value
.block__element--modifier-_-value
.block__element-_-modifier-_-value
.block__element-_-modifier--other-value
.block__element--modifier-_-other-value
.block__element-_-modifier-_-other-value
.block__element-_-other-modifier--value
.block__element--other-modifier-_-value
.block__element-_-other-modifier-_-value
.block__element-_-other-modifier--other-value
.block__element--other-modifier-_-other-value
.block__element-_-other-modifier-_-other-value
.block__other-element-_-modifier--value
.block__other-element--modifier-_-value
.block__other-element-_-modifier-_-value
.block__other-element-_-modifier--other-value
.block__other-element--modifier-_-other-value
.block__other-element-_-modifier-_-other-value
.block__other-element-_-other-modifier--value
.block__other-element--other-modifier-_-value
.block__other-element-_-other-modifier-_-value
.block__other-element-_-other-modifier--other-value
.block__other-element--other-modifier-_-other-value
.block__other-element-_-other-modifier-_-other-value
.other-block__element-_-modifier--value
.other-block__element--modifier-_-value
.other-block__element-_-modifier-_-value
.other-block__element-_-modifier--other-value
.other-block__element--modifier-_-other-value
.other-block__element-_-modifier-_-other-value
.other-block__element-_-other-modifier--value
.other-block__element--other-modifier-_-value
.other-block__element-_-other-modifier-_-value
.other-block__element-_-other-modifier--other-value
.other-block__element--other-modifier-_-other-value
.other-block__element-_-other-modifier-_-other-value
.other-block__other-element-_-modifier--value
.other-block__other-element--modifier-_-value
.other-block__other-element-_-modifier-_-value
.other-block__other-element-_-modifier--other-value
.other-block__other-element--modifier-_-other-value
.other-block__other-element-_-modifier-_-other-value
.other-block__other-element-_-other-modifier--value
.other-block__other-element--other-modifier-_-value
.other-block__other-element-_-other-modifier-_-value
.other-block__other-element-_-other-modifier--other-value
.other-block__other-element--other-modifier-_-other-value
.other-block__other-element-_-other-modifier-_-other-value
.block--_modifier
.other-block--_modifier
.block--_other-modifier
.other-block--_other-modifier
.block--_modifier--_value
.block--_modifier--_other-value
.other-block--_modifier--value
.other-block--modifier--_value
.other-block--_modifier--_value
.other-block--_modifier--other-value
.other-block--modifier--_other-value
.other-block--_modifier--_other-value
.block--_other-modifier--value
.block--other-modifier--_value
.block--_other-modifier--_value
.block--_other-modifier--other-value
.block--other-modifier--_other-value
.block--_other-modifier--_other-value
.other-block--_other-modifier--value
.other-block--other-modifier--_value
.other-block--_other-modifier--_value
.other-block--_other-modifier--other-value
.other-block--other-modifier--_other-value
.other-block--_other-modifier--_other-value
.block__element--_modifier
.block__element--_other-modifier
.block__other-element--_modifier
.block__other-element--_other-modifier
.other-block__element--_modifier
.other-block__element--_other-modifier
.other-block__other-element--_modifier
.other-block__other-element--_other-modifier
.block__element--_modifier--value
.block__element--modifier--_value
.block__element--_modifier--_value
.block__element--_modifier--other-value
.block__element--modifier--_other-value
.block__element--_modifier--_other-value
.block__element--_other-modifier--value
.block__element--other-modifier--_value
.block__element--_other-modifier--_value
.block__element--_other-modifier--other-value
.block__element--other-modifier--_other-value
.block__element--_other-modifier--_other-value
.block__other-element--_modifier--value
.block__other-element--modifier--_value
.block__other-element--_modifier--_value
.block__other-element--_modifier--other-value
.block__other-element--modifier--_other-value
.block__other-element--_modifier--_other-value
.block__other-element--_other-modifier--value
.block__other-element--other-modifier--_value
.block__other-element--_other-modifier--_value
.block__other-element--_other-modifier--other-value
.block__other-element--other-modifier--_other-value
.block__other-element--_other-modifier--_other-value
.other-block__element--_modifier--value
.other-block__element--modifier--_value
.other-block__element--_modifier--_value
.other-block__element--_modifier--other-value
.other-block__element--modifier--_other-value
.other-block__element--_modifier--_other-value
.other-block__element--_other-modifier--value
.other-block__element--other-modifier--_value
.other-block__element--_other-modifier--_value
.other-block__element--_other-modifier--other-value
.other-block__element--other-modifier--_other-value
.other-block__element--_other-modifier--_other-value
.other-block__other-element--_modifier--value
.other-block__other-element--modifier--_value
.other-block__other-element--_modifier--_value
.other-block__other-element--_modifier--other-value
.other-block__other-element--modifier--_other-value
.other-block__other-element--_modifier--_other-value
.other-block__other-element--_other-modifier--value
.other-block__other-element--other-modifier--_value
.other-block__other-element--_other-modifier--_value
.other-block__other-element--_other-modifier--other-value
.other-block__other-element--other-modifier--_other-value
.other-block__other-element--_other-modifier--_other-value
/******************************************************************************\
|* These SHOULD be matched *|
\******************************************************************************/
/* A normal class */
.one
.a
/* Classes with dash */
.a-b
.one-two
.one-two-three
.one-two-three-four
.one-two-three-i-n-f-i-n-i-t-y
/* BEM (Block Element Modifier) classes */
// Block Only
.block
.other-block
// Block + Element
.a__b
.a-b__element
.a-b__c-d
.block__element
.other-block__element
.block__other-element
.other-block__other-element
// Block + Modifier
.a--b
.a-b--c
.a--b-c
.a-b--c-d
.block--modifier
.other-block--modifier
.block--other-modifier
.other-block--other-modifier
// Block + Modifier Name + Modifier Value
.a--b--c
.a-b--c--d
.a--b-c--d
.a--b--c-d
.a-b--c--d-e
.a-b--c-d--e
.a--b-c--d-e
.block--modifier--value
.block--modifier--other-value
.other-block--modifier--value
.other-block--modifier--other-value
.block--other-modifier--value
.block--other-modifier--other-value
.other-block--other-modifier--value
.other-block--other-modifier--other-value
// Block + Element + Modifier
.a__b--c
.a__b--c-d
.a__b-c--d
.a__b-c--d-e
.a-b__c--d
.a-b__c--d-e
.a-b__d-e--f
.a-b__d-e--f-g
.block__element--modifier
.block__element--other-modifier
.block__other-element--modifier
.block__other-element--other-modifier
.other-block__element--modifier
.other-block__element--other-modifier
.other-block__other-element--modifier
.other-block__other-element--other-modifier
// Block + Element + Modifier Name + Modifier Value
.a__b--c--d
.a__b--c--d-e
.a__b--c-d--e
.a__b--c-d--e-f
.a__b-c--d--e
.a__b-c--d--e-f
.a__b-c--d-e--f
.a__b-c--d-e--f-g
.a-b__c--d--e
.a-b__c--d--e-f
.a-b__c--d-e--f
.a-b__c--d-e--f-g
.a-b__d-e--f--g
.a-b__d-e--f--g-h
.a-b__d-e--f-g--h
.a-b__d-e--f-g--h-i
.block__element--modifier--value
.block__element--modifier--other-value
.block__element--other-modifier--value
.block__element--other-modifier--other-value
.block__other-element--modifier--value
.block__other-element--modifier--other-value
.block__other-element--other-modifier--value
.block__other-element--other-modifier--other-value
.other-block__element--modifier--value
.other-block__element--modifier--other-value
.other-block__element--other-modifier--value
.other-block__element--other-modifier--other-value
.other-block__other-element--modifier--value
.other-block__other-element--modifier--other-value
.other-block__other-element--other-modifier--value
.other-block__other-element--other-modifier--other-value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.