Frequently Asked Questions
What is a regular expression?+
A regular expression, or regex, is a pattern used to match, search, or replace text. It's supported natively in JavaScript through the RegExp object and literals like /pattern/flags, and is used for form validation, search-and-replace, and parsing structured text.
What do the regex flags g, i, m, and s mean?+
g (global) finds all matches instead of stopping at the first one. i (case-insensitive) ignores letter case. m (multiline) makes ^ and $ match the start and end of each line rather than the whole string. s (dotall) makes the dot . also match newline characters.
What's the difference between .test() and .match() in JavaScript?+
RegExp.prototype.test() returns a boolean — true if the pattern matches anywhere in the string, false otherwise. String.prototype.match() returns the actual matched text (and capture groups), or all matches if the global flag is set, or null if nothing matched.
How do I escape special characters in a regex?+
Precede the special character with a backslash. Characters that need escaping to match them literally include . * + ? ^ $ ( ) | [ ] and the backslash itself. For example, to match a literal dot use \. instead of just a bare dot.
What are capture groups and named capture groups?+
Parentheses in a pattern create a capture group, letting you extract just that part of a match — for example (\d4)-(\d2) captures a year and month separately. Named capture groups use (?<name>...) so you can reference the captured value by name instead of by position.
Is my test string or pattern sent to a server?+
No. Matching runs entirely in your browser using JavaScript's built-in RegExp engine. Nothing you type is ever sent anywhere, logged, or stored — refresh the page and it's gone.