Regular Expression
A regular expression is a formal language for describing string patterns, defining matching rules with metacharacters and quantifiers; it is widely used for search, validation, and extraction.
Purpose
Provides a compact yet powerful string pattern-matching language, replacing hand-written parsing logic.
Mechanism
Composed of literal characters and metacharacters (. * + ? [] () {} \ | ^ $). Quantifiers control repetition (* zero or more, + one or more, ? zero or one, {n,m} a specified range). Grouping () captures, | alternates, [] is a character class, and \d \w \s are predefined classes. Engines match via NFA/DFA backtracking or automata.
Use cases
- Form input validation (emails, phone numbers)
- Log pattern extraction
- Find and replace (IDEs, sed)
- Lexer generation
Examples
- Input
/\d{3}-\d{4}/OutputMatches 123-45673 digits-4 digits
Common errors
- The greedy quantifier .* matches too much
- Use the non-greedy .*? or a precise character class
Related terms
Glob
Glob is shell-style file-path pattern matching that uses wildcards such as * ** ? [] to match file names; it is simpler than regex. GLOSSARY
Wildcard
Wildcards are simplified pattern-matching characters: * matches any sequence and ? matches a single character; commonly used for file-name and domain matching. GLOSSARY
Fuzzy Search
Fuzzy search is a search technique tolerant of spelling variations, matching approximate results based on edit distance, n-grams, or phonetic algorithms. GLOSSARY
Related tools
Regex Tester
Test regular expressions with match highlighting, capture groups, and replace preview. Free, private, and 100% client-side. TOOL
Regex Replace
Find and replace text using regular expressions. Free, private, 100% client-side. TOOL
Regex Explain
Regex Explain — pure client-side tool. Privacy-first, no server round-trip. TOOL
Regex Visualize
Render a regex as a Thompson NFA state diagram in Graphviz DOT format — ε-transitions, branches and quantifier loops visible; paste into any graphviz renderer. TOOL
Regex Validate Pattern
Regex Validate Pattern — pure client-side tool. Privacy-first, no server round-trip. TOOL
Regex Test Batch
Regex Test Batch — pure client-side tool. Privacy-first, no server round-trip. TOOL
Regex Escape String
Regex Escape String — pure client-side tool. Privacy-first, no server round-trip. TOOL