Awesome
<!--lint ignore awesome-heading--> <div align="center"> ย <sup>Shortcut URL: regex.cool
</sup>
Awesome Regex curates the best regular expression tools, tutorials, libraries, and other resources, covering all major regex flavors.
Regular expressions (regex or regexp) are a powerful and concise way to search, parse, and process text. They're built into many programming languages, text editors, IDEs, database engines, word processors, and other tools.
Contributions are welcome. Add links through pull requests (guidelines).
<details> <summary>๐ <b>Glossary</b></summary> <br>A brief glossary of regular expression terms as used in this list.
- Regex engine: Software that interprets and executes regular expressions, either built into a programming language or as a standalone library.
- Regex flavor: A unique set of regex syntax and behavior. Basic syntax is typically shared across flavors, but more advanced features often vary, sometimes in subtle or incompatible ways. A flavor might be shared across multiple implementations or programming languages.
- Ex: The โJavaScriptโ flavor is defined by the ECMAScript spec; implemented by multiple engines (V8, etc.).
- Ex: The โPCREโ flavor is the PCRE2 library, used by numerous programming languages and tools.
- Ex: Ruby swapped its regex implementation twice from version 1.8 โ 1.9 โ 2.0, so each used a distinct flavor. The Ruby 2.0+ flavor is referred to here as either โRubyโ or โOnigmoโ (the underlying regex library).
- Non-backtracking engine: A regex implementation that uses a non-backtracking algorithm and runs in linear time. This rules out worst case performance from superlinear backtracking, but it's slower with some patterns and precludes some useful features like backreferences.
Featured resource
<a href="https://github.com/slevithan/regex"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/slevithan/regex@4.1.0/media/regex-logo-dark.svg"> <img alt="regex logo" height="100" align="right" src="https://cdn.jsdelivr.net/gh/slevithan/regex@4.1.0/media/regex-logo.svg"> </picture> </a>Regex+ is a lightweight JavaScript library for more readable, high-performance, native JavaScript regexes with powerful features including free spacing, atomic groups, possessive quantifiers, subroutines, subroutine definition groups, and context-aware interpolation.
Contents
- Testers
- Syntax-free regex builders
- Visualizers
- Grep-like tools
- Tutorials
- Regex engines
- Performance
- Collections of patterns
- JavaScript regex libraries
- JavaScript regex evolution
- Books
- Articles
- Communities
- Miscellaneous
Testers
For building, testing, and playing with regexes.
- regex101 - Best free and best web-based tester.
- Flavors: Java, JavaScript, .NET, PCRE, RE2, Rust, and emulates Python.
- Includes regex debugger (PCRE only).
- RegexBuddy (<picture><img src="https://github.com/slevithan/awesome-regex/raw/main/media/windows.svg" title="Windows" height="13"></picture>, $40) - Best tester.
- Flavors: Emulates hundreds of flavors/versions, with deep knowledge of differences.
- Includes regex debugger.
- RegExr [GitHub] - Best open source tester.
- Flavors: JavaScript, PCRE.
- Languages: ๐บ๐ธ, ๐จ๐ณ (fork).
- RegexLearn [GitHub] - Best multilingual tester (JavaScript).
- Languages: ๐บ๐ธ, ๐น๐ท, ๐ท๐บ, ๐ช๐ธ, ๐จ๐ณ, ๐ฉ๐ช, ๐บ๐ฆ, ๐ซ๐ท, ๐ต๐ฑ, ๐ฐ๐ท, ๐ง๐ท, ๐จ๐ฟ, ๐ฌ๐ช.
- regexplained [GitHub] - Best tester for presentations (JavaScript).
Flavors
- JavaScript: RegViz.
- .NET: Regex Storm [GitHub].
- PCRE: PHP Live Regex.
- Python: Pythex.
- Ruby: Rubular.
- sed: GNU sed REPL.
Multiple flavors
- CyrilEx [GitHub] - Java, JavaScript, MySQL, PHP, Python, Ruby.
- Patterns (<picture><img src="https://github.com/slevithan/awesome-regex/raw/main/media/macos.svg" title="macOS" height="13"></picture>, $3) - Bash, Emacs, grep, Java, Oniguruma, PCRE, POSIX BRE, POSIX ERE, Ruby, sed.
- RegexPlanet [GitHub] - Go, Haskell, Java, JavaScript, .NET, Perl, PHP, PostgreSQL, Python, Ruby, Tcl, XRegExp.
Syntax-free regex builders
Build regexes without writing regex syntax or code.
- ChatGPT (and other LLMs) - Ex: "create a regex that matches
X
and explain it step by step". - RegexMagic (<picture><img src="https://github.com/slevithan/awesome-regex/raw/main/media/windows.svg" title="Windows" height="13"></picture>, $40) - Generate regexes using samples and rules.
- Flavors: Emulates hundreds of flavors/versions.
- Regex Generator [GitHub] - Generate simple regexes from a sample text.
- Regex.ai - Mark samples in a text and use AI to generate potential regexes.
Visualizers
Visualize how your regular expressions are structured or operate.
- Regex Vis [GitHub] - Create railroad diagrams, with visual editor. Flavor: JavaScript.
- Languages: ๐บ๐ธ, ๐จ๐ณ.
- Regulex [GitHub] - Create railroad diagrams. Flavor: JavaScript.
- Nodexr [GitHub] - Graphical editor with visual hierarchy. Flavor: .NET.
- Regex Nodes [GitHub] - Graphical editor with visual hierarchy. Flavor: JavaScript.
- Debuggex - Create railroad diagrams. Flavors: JavaScript, PCRE, Python.
- Regexper [GitLab] - Create railroad diagrams. Flavor: JavaScript.
Grep-like tools
Search and replace through files.
Command line
- ripgrep - Better and faster grep. Recursively searches directories while respecting gitignore rules and skipping hidden/binary files.
- Flavors: Rust (default), PCRE.
โ See also: Feature comparison of grep-like tools.
GUI
- Aba Search and Replace (<picture><img src="https://github.com/slevithan/awesome-regex/raw/main/media/windows.svg" title="Windows" height="13"></picture>, $30) - Displays matches as you type.
- PowerGREP (<picture><img src="https://github.com/slevithan/awesome-regex/raw/main/media/windows.svg" title="Windows" height="13"></picture>, $159) - Can search through archives, binary files, PDFs, docs/sheets, emails, etc., via its GUI or the command line.
- Flavors: Emulates hundreds of flavors/versions.
- PowerRename (<picture><img src="https://github.com/slevithan/awesome-regex/raw/main/media/windows.svg" title="Windows" height="13"></picture>) - Rename files using regexes.
Tutorials
Learn how to use regular expressions.
Traditional
- Regular-Expressions.info - Covers numerous regex flavors.
- The Modern JavaScript Tutorial: Regular expressions [GitHub] - Guide to using regexes in JavaScript.
- Languages: ๐บ๐ธ, ๐ช๐ธ, ๐ซ๐ท, ๐ฎ๐น, ๐ฏ๐ต, ๐ท๐บ, ๐บ๐ฆ, ๐จ๐ณ (partial for others).
- RexEgg - Detailed tutorial with advanced topics.
- learnbyexample [GitHub] - Ebooks on regexes (JavaScript, Python, Ruby) and command line text processing.
- Regular Expressions for Regular Folk [GitHub] - Visual, example-based ebook for beginners.
With interactive exercises
- RegexLearn [GitHub] - Interactive tutorial and practice problems.
- Languages: ๐บ๐ธ, ๐น๐ท, ๐ท๐บ, ๐ช๐ธ, ๐จ๐ณ, ๐ฉ๐ช, ๐บ๐ฆ, ๐ซ๐ท, ๐ต๐ฑ, ๐ฐ๐ท, ๐ง๐ท, ๐จ๐ฟ, ๐ฌ๐ช.
- RegexOne - Interactive tutorial and practice problems.
Videos
- Demystifying Regular Expressions - Great presentation for beginners, by Lea Verou at HolyJS 2017 (1hr 12m).
- Learn Regular Expressions In 20 Minutes - Live syntax walkthrough in a regex tester, by Kyle Cook.
- Many options for video courses are available on Udemy ($).
Regex engines
Major regex implementations, built into programming languages or as standalone libraries.
Documentation
Official regex references and guides.
Regex flavors
- Boost.Regex: Manual.
- C++: Regular expressions library.
- Hyperscan: Introduction.
- ICU: Regular Expressions.
- Java: Pattern, API.
- JavaScript: RegExp, Reference, Guide, Cheatsheet.
- .NET: Overview, Language, API.
- Onigmo: RE.
- Oniguruma: RE.
- PCRE2: Pattern, API.
- Perl: Syntax, Tutorial, Quick Start.
- Python: re.
- RE2: Syntax.
- Rust: regex, regex_lite.
โน๏ธ Raku (formerly Perl 6) reimagines regexes. See: Grammars (tutorial), Regexes (best practices).
Without own flavor
- Go: regexp - Flavor: RE2.
- MySQL: Regular Expressions - Flavor: ICU.
- PHP: Regular Expressions - Flavor: PCRE.
- Ruby: Regexp - Flavor: Onigmo.
- Swift: NSRegularExpression - Flavor: ICU.
Source code
Read or contribute to the code behind major regex implementations.
- Boost.Regex - Popular C++ regex library.
- Hyperscan - Intel's high-performance library, used for DPI.
- ICU - Unicode org's package with full Unicode support.
- Java: java.util.regex - JDK standard regexes.
- JavaScript:
- JavaScriptCore: RegExp - Regex engine used by Safari.
- V8: Irregexp - Regex engine used by Chrome, Edge, Firefox, etc.
- .NET: System.Text.RegularExpressions - Shared by all .NET languages (C#, VB, etc.).
- Onigmo - Forked from Oniguruma. Used by Ruby 2.0+.
- Oniguruma - Popular C regex library used by Ruby 1.9, TextMate grammars, etc.
- PCRE2 - Popular C regex library used by PHP, R, etc.
- Perl - See perlreguts.
- Python: re and regex - Standard and extended regex libraries.
- RE2 - Popular C++ regex library used by Go, etc. Non-backtracking engine.
- Rust: regex - Non-backtracking engine.
Flavor differences
Syntax and behavior differences between regex flavors.
- Ron Buckton: Regular Expression Feature Comparisons [GitHub].
- Regular-Expressions.info: Tools & Languages.
- Steven Levithan: Named capture, Lookbehind.
- Wikipedia: Comparison of regular expression engines.
Performance
Pattern and engine performance, benchmarks, and ReDoS prevention.
Crafting efficient regexes
- Runaway Regular Expressions: Catastrophic Backtracking - Exploration and solutions for superlinear backtracking.
- Book: High Performance JavaScript (2010) - Chapter 5: Strings and Regular Expressions.
- Book: Mastering Regular Expressions, 3rd Edition (2006) - Chapter 6: Crafting an Efficient Expression.
- Performance of Greedy vs. Lazy Regex Quantifiers - Illustrates the mechanics of backtracking.
โน๏ธ With backtracking engines, how you craft a regex can affect how fast it finds matches or reports failures.
<details> <summary>โณ๏ธ <b>Notable mentions</b></summary> <br>- Performance of Regular Expressions - On backtracking performance, with detailed examples.
Regex engine optimization
- Regular Expression Matching Can Be Simple And Fast - On non-backtracking engines. A follow up includes comparisons of RE2 and PCRE performance.
- Regular Expression Improvements in .NET 7 and .NET 5 - Includes detailed explanations of performance optimizations.
- ripgrep is faster than {grep, โฆ} - Includes details about what makes ripgrep and Rust's
regex
fast.
Benchmarking
- Cross-engine benchmarking libraries: rebar, regex-benchmark.
- Boost.Regex: Performance - Compares Boost, C++
std::regex
, and others.
ReDoS checkers
- regex.rip - Test a regex for ReDoS vulnerability.
- recheck [home] - JavaScript and Scala library for detecting ReDoS vulnerability. Can be used as an ESLint plugin.
- vuln-regex-detector - Perl library for detecting ReDoS vulnerability.
โ ๏ธ These tools have limitations on supported syntax.
Collections of patterns
Prewritten regexes for specific tasks.
- Book: Regular Expressions Cookbook, 2nd Edition (2012) - High-quality solutions with detailed explanations.
- Flavors: Java, JavaScript, .NET, PCRE, Perl, Python, Ruby, XRegExp.
- Regex DB - Solutions include basic descriptions and examples of matching and non-matching text.
Many regexes found online are low quality. It's risky to use regexes you don't fully understand in code, since they might have false positives/negatives, be vulnerable to performance problems with certain target strings, or assume a different regex flavor.
</details>JavaScript regex libraries
Open source JavaScript libraries for advanced regex use and processing.
Alternative regex builders and engines
- Regex+ - A template tag for extended, readable, high-performance JavaScript regexes.
- Oniguruma-To-ES - Convert Oniguruma patterns to native JavaScript regexes.
- XRegExp [home] - Extended regex syntax, flags, and utils; useful for backcompat.
- incr-regex-package - Partial/incremental matching, used by react-rxinput for input validation with a regex mask.
- Use other engines via WASM bindings: node-re2 (RE2), rregex (Rust's
regex
), vscode-oniguruma (Oniguruma).
Abstracted regex syntax
- Rexx - A template tag that uses structured syntax with variables and comments.
- Melody [docs] - A language that compiles to regexes.
- Compose with functions: compose-regexp.js, VerbalExpressions (implementations for many languages), magic-regexp [home], Super Expressive [playground].
Regex processors
- AST builders: regexpp (used by ESLint), regexp-tree (includes optimizer, etc.), regjsparser/regjsgen.
- AST Explorer: RegExp - View ASTs generated by regexp-tree, regexpp, and regjsparser.
- regexp-ast-analysis [docs] - Analyze AST nodes produced by regexpp.
- Highlight regex syntax: Regex Colorizer [home], CodeMirror PCRE mode.
- Find regex mistakes and improvements: eslint-plugin-regexp [home], eslint-plugin-optimize-regex.
- Generate strings that match a given regex: randexp.js, regex-to-strings.
- Generate a regex from given strings: regexgen.
JavaScript regex evolution
The history of improvements to regular expressions in the JavaScript standard. Starting with ES2018, includes links to the TC39 proposals where features were developed and discussed.
- ES3 (1999) introduced regular expressions.
- ES5 (2009) fixed unintuitive behavior by creating a new object every time regex literals are evaluated [explainer], and allowed regex literals to use unescaped forward slashes within character classes (
/[/]/
). - ES6/ES2015 added: [explainer]
- Flag
y
(sticky
), which anchors matches tolastIndex
. - Flag
u
(unicode
) [explainer] [2016 spec fix], which adds Unicode code point escapes via\u{โฆ}
, strict errors (for unreserved escapes, octal escapes, quantified lookahead, and unescaped special characters in some contexts), Unicode case-folding for flagi
, and code point matching (with impact on quantifiers, character classes, ranges, and built-in sets). - Getter
RegExp.prototype.flags
, the ability to copy a regex usingRegExp
(optionally with new flags), and support for subclassingRegExp
(along withRegExp.prototype[Symbol.match
/replace
/search
/split]
andRegExp[Symbol.species]
).
- Flag
- ES2018 added flag
s
(dotAll
), lookbehind, named capture, and Unicode properties (via\p{โฆ}
and\P{โฆ}
which require flagu
; see list). - ES2020 added string method
matchAll
(which returns an iterator), plusRegExp.prototype[Symbol.matchAll]
. - ES2022 added flag
d
(hasIndices
), which provides start/end indices for matched substrings. - ES2024 added flag
v
(unicodeSets
) [explainer] as an upgrade to flagu
, which adds a set of multicharacter "properties of strings" to\p{โฆ}
, multicharacter elements within character classes via\p{โฆ}
and\q{โฆ|โฆ}
, nested character classes, set operators[โฆ--โฆ]
and[โฆ&&โฆ]
, and different escaping rules within character classes. It also fixes case-insensitive matching for\p
and\P
within negated[^โฆ]
.
<details> <summary>โ <b>See also</b></summary> <br>Each edition from ES2019 to ES2023 added additional Unicode properties that can be used via
\p{โฆ}
and\P{โฆ}
(see lists). ES2021 added string methodreplaceAll
, although, when given a regex, the only difference from ES3'sreplace
is that it throws if not using flagg
.
- Regexes Got Good: The History And Future Of Regular Expressions In JavaScript
- Backcompat libraries: regexpu, regenerate (Unicode property sets).
- Chrome's
l
(linear
) regex flag, behind a V8 flag [explainer] [how to run]. - Can I use - Up-to-date browser support tables for individual features.
- Duplicate named capturing groups (2022) - Ex:
(?<a>โฆ)|(?<a>โฆ)
. - Extended mode and comments (2021) - Flag
x
(extended
) with insignificant whitespace and line comments (#โฆ
), plus inline comments via(?#โฆ)
. - Pattern modifiers (2021) - Ex:
(?ims:โฆ)
,(?-ims:โฆ)
,(?i-ms:โฆ)
. - Atomic operators (2021) - Atomic groups via
(?>โฆ)
and possessive quantifiers (ex:*+
,++
). - Buffer boundaries (2021) - Anchors
\A
and\z
, not affected by flagm
. - \R escape (2021) - Outside character classes,
\R
matches any line terminator. - Restrict subclassing support in built-ins (2020) - Scaled back
RegExp
subclassing. - RegExp escaping (2015) -
RegExp.escape
. - Legacy RegExp features (2015) - Standardization of legacy features.
Books
A curated list of regex books.
- Regular Expressions Cookbook, 2nd Edition (2012) by Jan Goyvaerts and Steven Levithan - Regex tutorial with code samples for eight programming languages, 100+ regex recipes for practical problems, and a deep focus on cross-flavor differences.
- Flavors: Java, JavaScript, .NET, PCRE, Perl, Python, Ruby, XRegExp.
- Mastering Regular Expressions, 3rd Edition (2006) by Jeffrey Friedl - A computer science classic, best for people who already know the basics. Includes good coverage of crafting efficient regexes.
- Flavors: Dedicated chapters on Java, .NET, Perl, and PHP (PCRE), with more limited coverage of Python, Tcl, command line tools, etc.
- Introducing Regular Expressions (2012) by Michael Fitzgerald - An intro for programmers new to regular expressions that sticks to the basics.
Articles
A curated list of regex articles.
- The World's Shortest Regex Compiler? and a follow up on optimization - Introduction to writing a non-backtracking regex engine (in JavaScript).
- Regex Legends: The People Behind the Magic - Influential people behind the technology.
- Fun With .NET Regex Balancing Groups - Advanced usage of a .NET-only regex feature.
Communities
Discuss, assist, and get help with regular expressions.
Miscellaneous
Other interesting, fun, and useful stuff.
- Chrome extension: Regex - Regex search on webpages via
Ctrl+Shift+F
. - Quiz: regex101 Regex Quiz - Requires sign-in.
- Games: Regex Crossword, regexle, Regex Machina ($).
- Comics: xkcd, Garabato Kid.