bun i -D @archoleat/reglib
This library provides a collection of useful regular expressions for various use cases. Below is a list of the exported regex patterns along with their explanations:
-
ATTRIBUTE_REGEX
- Pattern:
\[[^\]]+\]
. - Description: Matches an attribute in square brackets.
- Example: Matches
[attr]
,[data-test]
, but not[attr or attr]
.
- Pattern:
-
CLASS_REGEX
- Pattern:
\.[a-z0-9_-]+
. - Description: Matches a CSS class name starting with a dot (.).
- Example: Matches
.class
,.my-class
,.class_name
, but notclass
or.class!
.
- Pattern:
-
BLOCK_REGEX
- Pattern:
[a-z][a-z0-9]*(-[a-z0-9]+)*
. - Description: Matches a BEM block name.
- Example: Matches
block
,my-block
,block-name
, but notBlock
orblock!
.
- Pattern:
-
ELEMENT_REGEX
- Pattern:
(__[a-z0-9]+(-[a-z0-9]+)*)
. - Description: Matches a BEM element name.
- Example: Matches
__element
,__my-element
, but notelement
or__element!
.
- Pattern:
-
MODIFIER_REGEX
- Pattern:
(--[a-z0-9]+(-[a-z0-9]+)*)
. - Description: Matches a BEM modifier name.
- Example: Matches
--modifier
,--my-modifier
, but notmodifier
or--modifier!
.
- Pattern:
-
SIBLING_REGEX
- Pattern:
(?:[^ ,{}]+\s*)?\+\s*[^ ,{}]+
. - Description: Matches a sibling selector in CSS.
- Example: Matches
+ p
,div + p
,.class + .another-class
, but notdiv > p
.
- Pattern:
-
CHILD_REGEX
- Pattern:
(?:[^ ,{}]+\s*)?>\s*[^ ,{}]+
. - Description: Matches a child selector in CSS.
- Example: Matches
> p
,div > p
,.class > .another-class
, but notdiv + p
.
- Pattern:
-
ATTRIBUTE_SIBLING_REGEX
- Pattern:
\[[^\]]+\]\s*\+\s*[^ ,{}]+
. - Description: Matches an attribute selector followed by a sibling selector.
- Example: Matches
[attr] + div
,[data-test] + .class
.
- Pattern:
-
ATTRIBUTE_CHILD_REGEX
- Pattern:
\[[^\]]+\]\s*>\s*[^ ,{}]+
. - Description: Matches an attribute selector followed by a child selector.
- Example: Matches
[attr] > div
,[data-test] > .class
.
- Pattern:
-
CLASS_SIBLING_REGEX
- Pattern:
\.[a-z0-9_-]+\s*\+\s*[^ ,{}]+
. - Description: Matches a class selector followed by a sibling selector.
- Example: Matches
.class + div
,.my-class + .another-class
.
- Pattern:
-
CLASS_CHILD_REGEX
- Pattern:
\.[a-z0-9_-]+\s*>\s*[^ ,{}]+
. - Description: Matches a class selector followed by a child selector.
- Example: Matches
.class > div
,.my-class > .another-class
.
- Pattern:
-
NESTED_ATTRIBUTE_SIBLING_REGEX
-
Pattern:
&\[[^\]]+\]\s*\+\s*[^ ,{}]+
. -
Description: Matches a nested attribute selector followed by a sibling selector.
-
Example: Matches
&[attr] + div
,&[data-test] + .class
.
-
-
NESTED_ATTRIBUTE_CHILD_REGEX
-
Pattern:
&\[[^\]]+\]\s*>\s*[^ ,{}]+
. -
Description: Matches a nested attribute selector followed by a child selector.
-
Example: Matches
&[attr] > div
,&[data-test] > .class
.
-
-
NESTED_CLASS_SIBLING_REGEX
- Pattern:
&\.[a-z0-9_-]+\s*\+\s*[^ ,{}]+
. - Description: Matches a nested class selector followed by a sibling selector.
- Example: Matches
&.class + div
,&.my-class + .another-class
.
- Pattern:
-
NESTED_CLASS_CHILD_REGEX
- Pattern:
&\.[a-z0-9_-]+\s*>\s*[^ ,{}]+
. - Description: Matches a nested class selector followed by a child selector.
- Example: Matches
&.class > div
,&.my-class > .another-class
.
- Pattern:
-
NESTED_ATTRIBUTE_REGEX
- Pattern:
&\[[^\]]+\]
. - Description: Matches a nested attribute selector.
- Example: Matches
&[attr]
,&[data-test]
.
- Pattern:
-
NESTED_CLASS_REGEX
- Pattern:
&\.[a-z0-9_-]+
. - Description: Matches a nested class selector.
- Example: Matches
&.class
,&.my-class
.
- Pattern:
-
FONT_FILE_NAME_REGEX
-
Pattern: A complex regex for matching font file names.
-
Description: Matches font file names based on family, weight, italic, variable, and extension.
-
Example: Matches
Roboto-Bold.woff2
,OpenSans-Italic-Variable.ttf
.More info validate-font-file-name
-
Please read CONTRIBUTING to start contributing.
This project is licensed under the MIT license.