Giter Club home page Giter Club logo

awesome-regex's Introduction

Awesome Regex

Awesome ย Shortcut URL: regex.cool

Awesome Regex curates the best regular expression tools, tutorials, libraries, and other resources. It covers all major regex flavors, and currently includes especially deep coverage of regular expressions in JavaScript.

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) or create an issue to start a discussion.

๐Ÿ“– Glossary

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.

Contents

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 (, $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).
โœณ๏ธ Notable mentions

Flavors

Multiple flavors

  • CyrilEx [GitHub] - Java, JavaScript, MySQL, PHP, Python, Ruby.
  • Patterns (, $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 (, $40) - Generate regexes using samples and rules.
    • Flavors: Emulates hundreds of flavors/versions.
โœณ๏ธ Notable mentions
  • 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.
โœณ๏ธ Notable mentions
  • 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 (, $30) - Displays matches as you type.
  • PowerGREP (, $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.
  • RegexRenamer () - Rename files using regexes.

Tutorials

Learn how to use regular expressions.

Traditional

โœณ๏ธ Notable mentions

With interactive exercises

  • RegexLearn [GitHub] - Interactive tutorial and practice problems.
    • Languages: ๐Ÿ‡บ๐Ÿ‡ธ, ๐Ÿ‡น๐Ÿ‡ท, ๐Ÿ‡ท๐Ÿ‡บ, ๐Ÿ‡ช๐Ÿ‡ธ, ๐Ÿ‡จ๐Ÿ‡ณ, ๐Ÿ‡ฉ๐Ÿ‡ช, ๐Ÿ‡บ๐Ÿ‡ฆ, ๐Ÿ‡ซ๐Ÿ‡ท, ๐Ÿ‡ต๐Ÿ‡ฑ, ๐Ÿ‡ฐ๐Ÿ‡ท, ๐Ÿ‡ง๐Ÿ‡ท, ๐Ÿ‡จ๐Ÿ‡ฟ, ๐Ÿ‡ฌ๐Ÿ‡ช.
  • RegexOne - Interactive tutorial and practice problems.

Videos

Regex engines

Major regex implementations, built into programming languages or as standalone libraries.

Documentation

Official regex references and guides.

Regex flavors

โ„น๏ธ Raku (formerly Perl 6) reimagines regexes. See: Grammars (tutorial), Regexes (best practices).

Without own flavor

Source code

Read or contribute to the code behind major regex implementations.

Flavor differences

Syntax and behavior differences between regex flavors.

Performance

Pattern and engine performance, benchmarks, and ReDoS prevention.

Crafting efficient regexes

โ„น๏ธ With backtracking engines, how you craft a regex can affect how fast it finds matches or reports failures.

Regex engine optimizations

Benchmarking

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.

โš ๏ธ Word of warning

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.

JavaScript regex libraries

Open source JavaScript libraries for advanced regex use and processing.

Alternative regex builders and engines

  • regex - Context-aware regex template tag with advanced features and best practices built-in.
  • 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.
  • node-re2 - Bindings for RE2, a non-backtracking engine.
  • rregex - Bindings for Rust's regex, a non-backtracking engine.

Abstracted regex syntax

Regex processors

JavaScript regex evolution

A concise history of improvements to regular expressions in the JavaScript standard, with links to the TC39 proposals where features were developed and discussed.

  • ES3 (1999) introduced powerful regular expressions, though limited compared to other major flavors.
  • 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 clases (/[/]/).
  • ES6/ES2015 added: [explainer]
    • Flag y (sticky), which anchors matches to lastIndex.
    • Flag u (unicode) [explainer] [2016 spec fix], which adds Unicode code point escapes via \u{โ€ฆ}, strict errors (for unreserved letter escapes, octal escapes, escaped literal digits, and unescaped special characters in some contexts), Unicode case-folding for flag i, and code-point-based matching (with impact on quantifiers, character classes, character class ranges, and built-in sets like . and \W).
    • Getter RegExp.prototype.flags.
    • Can subclass RegExp, plus RegExp.prototype[Symbol.match/replace/search/split] and RegExp[Symbol.species] for use in subclasses.
    • Use RegExp to copy a regex, optionally with new flags.
  • ES2018 added flag s (dotAll), lookbehind, named capture, and Unicode properties via \p{โ€ฆ} and \P{โ€ฆ} behind flag u (see list).
  • ES2020 added string method matchAll (which returns an iterator), plus RegExp.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 flag u (can't be used together), 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 doubly-negated [^\P{โ€ฆ}].

Each edition from ES2019 to ES2023 added additional Unicode properties that can be used via \p{โ€ฆ} and \P{โ€ฆ} (see lists). ES2021 added replaceAll, which optionally accepts a RegExp, but it behaves identically to ES3's replace when given a regex as the search.

โž• See also
๐Ÿ”ฎ Future: Active proposals

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.

Communities

Discuss, assist, and get help with regular expressions.

Miscelaneous

Other interesting, fun, and useful stuff.

awesome-regex's People

Contributors

slevithan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.