Explanation:
Matches cat, cut, cot, or any three-letter word starting with c and ending with t.
Caret (^) — Start of String
The caret matches the start of a string.
Explanation:
Checks if the string starts with Hello.
Dollar ($) — End of String
The dollar sign matches the end of a string.
Explanation:
Checks if the string ends with JavaScript.
Asterisk (*) — Zero or More Times
The asterisk matches the previous character zero or more times.
Explanation:
Matches col, cool, coool, and similar patterns.
Plus (+) — One or More Times
The plus matches the previous character one or more times.
Explanation:
Matches cool but not col.
Question Mark (?) — Optional or Lazy
The question mark makes the previous character optional (zero or one time).
Explanation:
Matches both color and colour.
Pipe (|) — OR Operator
The pipe symbol works as OR between patterns.
Explanation:
Matches if either cats or dogs exists.
Parentheses ( ) — Grouping
Parentheses group parts of a pattern together
Explanation:
Matches repeated groups of ab.
Square Brackets [ ] — Character Classes
Square brackets define a set of allowed characters.
Explanation:
Matches bat, cat, or rat.
Curly Braces { } — Exact Repetitions
Curly braces define exact or range-based repetitions.
Explanation:
Matches exactly 4 digits.
Summary of RegExp Metacharacters
| Metacharacter | Meaning |
|---|---|
. | Any single character |
^ | Start of string |
$ | End of string |
* | Zero or more |
+ | One or more |
? | Optional |
| ` | ` |
( ) | Grouping |
[ ] | Character set |
{ } | Repetition count |
\ | Escape character |
Conclusion
RegExp metacharacters in JavaScript control how patterns match text. By understanding symbols like ., ^, $, *, +, ?, |, grouping, character sets, and repetition rules, complex text matching tasks become simple and reliable in JavaScript applications.