bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/JavaScript/Working with Data
JavaScript•Working with Data

JavaScript RegExp Patterns

Revised July 2025

Flags can be added to a regexp pattern to Modify its behavior:

FlagDescription
/dPerforms substring matches (new 2022)
/gPerforms a global match (find all)
/iPerforms case-insensitive matching
/mPerforms multiline matching
/sAllows . (dot) to match line terminators (new 2018)
/uEnables Unicode support (new 2015)
/vAn upgrade to the /u flag for better Unicode support (new 2025)
/yPerforms a "sticky" search (new 2015)

Revised July 2025

A character class is one or more characters enclosed in square brackets [ ] :

ClassDescription
[a]Matches the character between the brackets
[^a]Matches all characters NOT between the brackets
[abc]Matches all characters between the brackets
[^abc]Matches all characters NOT between the brackets
[a-z]Matches all characters in the range from a to z
[^a-z]Matches all characters NOT in the range from a to z
[0-9]Matches all characters in the range from 0 to 9

Revised July 2025

Metacharacters are characters with a special meaning:

abMatches a or b
.Matches any (wildcard) character except line terminators
\wMatches word characters (alphanumeric and _)
\WMatches non-word characters
\dMatches digits (0-9)
\DMatches non-digit characters
\sMatches whitespace characters (space, tab, newline)
\SMatches non-whitespace character
[\b]Matches backspace characters
\0Matches NULL characters
\nMatches new line characters
\fMatches form feed characters
\rMatches carriage returns characters
\tMatches tab characters
\vMatches vertical tab characters
\p{}Matches characters with given Unicode Property (new 2018)
\P{}Matches character NOT with the given Unicode Property (new 2018)
\dddMatches a character by the octal number ddd
\xhhMatches a character by the hexadecimal number hh
\uhhhhMatches a Unicode character by the hex number hhhh

Revised July 2025

Assertions consist of Boundaries and Lookarounds .

Boundaries matches at the beginning or the end of lines and words, Lookarounds mathes previos or subsequent patterns.

CharDescription
^Matches from beginning of a string, or the beginning of a line if the m (multiline) flag is set
$Matches from the end of a string, or the end of a line if the m (multiline) flag is set
\bMatches from the beginning or end of a word
\BMatches NOT from the beginning or end of a word
(?=...)Matches the subsequent string
(?!...)Matches NOT the subsequent string
(?<=...)Matches the previous string (new 2018)
(?<!...)Matches NOT the previous string (new 2018)

RexExp Quantifiers

Quantifiers indicate the numbers of characters or expressions to match:

CodeDescription
x+Matches at least one x
x*Matches zero or more occurrences of x
x?Matches zero or one occurrences of x
x{n}Matches n occurences of x
x{n,m}Matches from n to m occurences of x
x{n,}Matches n or more occurences of x

Previous

RegExp Quantifiers

Next

JavaScript RegExp Objects

This chapter

Overview
37

Lessons

216m

Read time

1. JavaScript Strings2. JavaScript Numbers3. JavaScript Dates4. JavaScript Arrays5. JavaScript Sets6. JavaScript Maps7. JavaScript Math Object8. JavaScript RegExp9. JavaScript String Templates10. JavaScript Number Methods11. JavaScript Date Formats12. JavaScript Array Methods13. JavaScript Set Methods14. JavaScript Map Methods15. JavaScript Random16. JavaScript RegExp Flags17. JavaScript String Methods18. JavaScript Number Properties19. JavaScript Get Date Methods20. JavaScript Array Search21. JavaScript Set Logic22. JavaScript WeakMap23. RegExp Character Classes24. JavaScript String Search25. JavaScript Bitwise Operations26. JavaScript Set Date Methods27. JavaScript Array Sort28. JavaScript WeakSet29. RegExp Meta Characters30. JavaScript BigInt31. JavaScript Array Iterations32. Regular Expression Assertions33. JavaScript Array Const34. RegExp Quantifiers35. JavaScript RegExp Patterns36. JavaScript RegExp Objects37. RegExp Methods

On this page

Revised July 2025Revised July 2025Revised July 2025Revised July 2025RexExp Quantifiers