The JavaScript version.
- Metacharacters
.: Any one character except newline, same as[^\n].\d,\D: Any one digit/non-digit character (where digits are[0-9]).\w,\W: Any one word/non-word character. For ASCII, word characters are[a-zA-Z0-9_].\s,\S: Any one space/non-space character. For ASCII, whitespace characters are[ \n\r\t\f].
- Occurrence Indicators
+: One or more, e.g.[0-9]+matches 1 or more digits, such as "123", "0000".*: Zero or more (accepts the above + empty strings).?: Zero or one (optional), e.g., [+-]? matches an optional "+", "-", or an empty string.{}{m,n}:mton(both inclusive).{m}: Exactlymtimes.{m,}:mor more times (m+).
- Position Anchors
^: Start of line, e.g.^[0-9]$matches a numeric string.$: End of line\b: Boundary of word, i.e., start-of-word or end-of-word. E.g., \bcat\b matches the word "cat" in the input string.\B: Inverse of\b, i.e. non-start-of-word or non-end-of-word.
- Parenthesized Back References
():
- Character Class (or Bracket List)
[][...]: Accept any one of the character within the bracket.[.-.]: Accept any one of the characters in the range, e.g.[0-9],[A-Za-z].[^...]: Rejects any one of the character, e.g.[^0-9]matches any non-digit.- Only ^, -, ], \ require escape sequence inside the bracket list.
|: OR operator, e.g.four|4accepts "four" or "4".\: Escape sequence to accept a char with special meaning in regex.- Regex recognizes common escape sequences such as
\nfor newline,\tfor tab,\rfor carriage-return,\nnnfor a up to 3-digit octal number,\xhhfor a two-digit hex code,\uhhhhfor a 4-digit Unicode,\uhhhhhhhhfor a 8-digit Unicode.
- Regex recognizes common escape sequences such as