Qaynaq LABS · TOOLS

REGEX · JAVASCRIPT

Regex explained

^[a-zA-Z0-9\s\-\(\)]{10,}$

Matches strings that are at least 10 characters long and consist only of alphanumeric characters, whitespace, hyphens, or parentheses.

Token-by-token breakdown

TokenMeaningExample
^ Anchor: asserts position at the start of the string Start of 'abc123- (x)'
[ Start of a character class N/A
a-z Character class: lowercase letters a through z 'a', 'm', 'z'
A-Z Character class: uppercase letters A through Z 'A', 'M', 'Z'
0-9 Character class: digits 0 through 9 '0', '5', '9'
\s Character class: whitespace characters (space, tab, newline, etc.) ' ', '\t', '\n'
\- Character class: literal hyphen (escaped to avoid being part of a range) '-'
\( Character class: literal opening parenthesis (escaped) '('
\) Character class: literal closing parenthesis (escaped) ')'
] End of the character class N/A
{10,} Quantifier: match the preceding token (character class) 10 or more times 10+ characters from the class
$ Anchor: asserts position at the end of the string End of 'abc123- (x)'

Matches

  • abc123- (x)
  • Hello World 123
  • A-B-C-D-E-F-G-H-I-J
  • 1234567890
  • ( )
  • a1 b2 c3 d4 e5 f6

Does not match

  • abc123
  • abc123- (x)a
  • abc123- (x)
  • abc@123- (x)
  • abc123- (x)
  • a1b2c3d4e5
  • abc123- (x)!

Common pitfalls

  • Forgetting to escape special characters like '-', '(', and ')' in the character class.
  • Assuming '\s' only matches space characters (it also matches tabs, newlines, etc.).
  • Not accounting for Unicode whitespace characters if the input might contain them.
  • Assuming the pattern matches exactly 10 characters (it matches 10 or more).

Performance notes

No catastrophic backtracking risk due to the fixed quantifier and simple character class. The pattern is efficient for typical use cases. Anchors ensure full-string matching, which is optimal.

About regular expressions

Regular expressions are tiny programs that match patterns in text. They're powerful and notoriously cryptic — most engineers can write them but few can read them confidently. Qaynaq Labs' regex explainer breaks any pattern into its constituent tokens, shows what each one does, and runs through both matching and non-matching examples so you can verify the logic.

Different regex flavors (JavaScript, PCRE, Python, Go) have subtle differences in syntax and supported features. Pick your flavor in the input — the explainer accounts for it.

Frequently asked

Does this pattern match strings with exactly 10 characters?

No, the quantifier {10,} matches strings with 10 or more characters.

Does this pattern allow Unicode letters or digits?

No, it only allows ASCII letters (a-z, A-Z) and digits (0-9).

Why are parentheses escaped in the character class?

Parentheses are special regex metacharacters, so they must be escaped to be treated as literal characters.

Does this pattern match strings with leading or trailing whitespace?

Yes, because '\s' is included in the character class.