Regex cheatsheet

    Quick reference for regular expression syntax, classes and flags.

    Loading tool…

    About the regex cheatsheet

    A filterable reference for regular expression syntax: character classes, quantifiers, anchors, groups, lookaround and flags, plus a handful of patterns worth stealing outright. Filter by symbol or by what you are trying to do, and click any snippet to copy it. Syntax shown is JavaScript, which is close to PCRE for everyday use.

    Frequently asked questions

    Greedy or lazy quantifiers?

    Greedy matches as much as possible and backtracks; lazy takes the shortest match. Scraping content between tags is the classic case where .*? saves you from swallowing the whole document.

    Should I validate email addresses with a regex?

    Only loosely. The full grammar is notoriously baroque, and strict patterns reject valid addresses. Check for an @ with something either side, then send a confirmation message.

    Often used alongside