These are metacharacters with special meaning in regex. To match them literally, prefix with a backslash: \.\*\+ etc.
] ^ - \
Inside a character class [...], only these characters need escaping (and - only when not at the start or end).
Frequently Asked Questions
What is a regular expression (regex)?▼
A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. It is used for string matching, searching, and text manipulation in programming languages, text editors, and command-line tools. Regex is supported in virtually every programming language including JavaScript, Python, Java, Go, PHP, and Ruby.
What is the difference between greedy and lazy quantifiers?▼
Greedy quantifiers (*, +, {n,m}) match as much text as possible while still allowing the overall pattern to succeed. Lazy (non-greedy) quantifiers (*?, +?, {n,m}?) match as little text as possible. For example, given the string <b>bold</b>, the greedy pattern <.*> matches the entire string, while the lazy pattern <.*?> matches only <b>.
What are lookahead and lookbehind assertions?▼
Lookahead and lookbehind are zero-width assertions that match a position in the string without consuming characters. A positive lookahead (?=...) asserts that what follows matches the pattern. A negative lookahead (?!...) asserts that what follows does not match. Similarly, positive lookbehind (?<=...) and negative lookbehind (?<!...) check what precedes the current position. They are useful for conditional matching without including the checked text in the result.
How do I match special characters literally in regex?▼
To match regex special characters (metacharacters) literally, you need to escape them with a backslash (\). The characters that need escaping are: . * + ? ^ $ { } [ ] ( ) | \. For example, to match a literal dot, use \. instead of just .. Inside a character class [...], most special characters lose their meaning except for ], \, ^, and - which still need escaping in certain positions.