正在加载,请稍候…

Regex cheat sheet

A comprehensive regex cheat sheet with common patterns for email, URL, phone, date, IP address, and more. Copy-ready examples with explanations for JavaScript, Python, and PCRE.

How to Use

  1. Step 1: Browse the regex cheat sheet.
  2. Step 2: Click any row to copy the expression.
  3. Step 3: Use the table of contents on the right to navigate sections.

Frequently Asked Questions

What is a regular expression?

A regular expression (regex) is a pattern used to match character combinations in strings, widely used for search, replace, and validation.

How do I test a regex?

Use the Regex Tester tool on this site to test and debug regular expressions in real-time.

What is the difference between greedy and lazy quantifier matching?

Greedy (default) matches as much as possible: .* matches to the end of the string. Lazy (add ? after quantifier: .*?) matches as little as possible, stopping at the first match. For example: /<.*>/ greedily matches the whole line; /<.*?>/ lazily matches just the first complete tag.

What is the difference between greedy and non-greedy matching in regex?

Greedy quantifiers (* + ?) match as many characters as possible; non-greedy/lazy quantifiers (*? +? ??) match as few as possible. Example: for the string '<a>foo</a><b>bar</b>', <.*> greedy-matches the entire string, while <.*?> matches only the first '<a>'. This is critical when extracting HTML tag content — always use non-greedy to avoid matching from the first opening tag to the last closing tag.