Report

Help us improve this tool

Regex Memo

Quick reference guide for regular expression syntax including character classes, quantifiers, boundaries, groups, and flags. Free online regex cheat sheet.

O M T

What is a Regex Memo?

A regex memo (regular expression cheat sheet) is a quick reference guide that summarizes the syntax and usage of regular expressions. Regular expressions are powerful patterns used to match, search, and manipulate text. This regex reference covers character classes, quantifiers, boundaries, groups, lookaheads, and common flags to help you write and understand regex patterns faster.

How to Use This Regex Reference

Browse the tables below to find the regex pattern you need. Each table covers a specific category such as character classes, quantifiers, or boundaries. The Expression column shows the pattern syntax and the Description column explains what it matches. Use the notes under each table for important details about escaping, character sets, and grouping.

Common Regex Flags

Flags modify how a regular expression is interpreted. The most common flags include g for global search (find all matches), i for case-insensitive matching, m for multiline mode where ^ and $ match start and end of each line, s for dotall mode where . matches newline characters, and u for Unicode mode that treats the pattern as a sequence of Unicode code points.

Practical Regex Use Cases

Regular expressions are widely used in programming, data validation, text processing, and search operations. Common use cases include validating email addresses and phone numbers, extracting URLs from text, parsing log files, find-and-replace operations in code editors, form input validation, and data scraping. Most programming languages including JavaScript, Python, PHP, and Java support regex with similar syntax.

Regex Testing Tips

When writing regex patterns, start with a simple pattern and gradually add complexity. Use our Regex Tester to verify your patterns against sample text. Remember that regex can be greedy by default, matching as much text as possible. Use lazy quantifiers like *? or +? to match as little as possible. Test edge cases including empty strings, special characters, and very long inputs.

Frequently Asked Questions

What does \\d match in a regular expression?

The \\d pattern matches any digit character from 0 to 9. It is equivalent to the character class [0-9]. The uppercase \\D is its inverse and matches any non-digit character.

What is the difference between * and + quantifiers?

The * quantifier matches zero or more occurrences of the preceding pattern, while the + quantifier matches one or more occurrences. For example, a* matches empty string, "a", "aa", etc. But a+ only matches "a", "aa", etc. and does not match an empty string.

How do I match a literal dot in regex?

To match a literal dot (period), you must escape it with a backslash as \\.. Without escaping, the dot is a special character that matches any single character except newline. Inside a character set like [.], the dot is treated as a literal period and does not need escaping.

What is the difference between capturing and non-capturing groups?

A capturing group (pattern) both matches the pattern and stores the matched text for later reference via backreferences like \\1 or $1. A non-capturing group (?:pattern) matches the pattern but does not store the matched text, which is useful for grouping without the overhead of capturing.

What are lookahead and lookbehind assertions?

Lookahead and lookbehind are zero-width assertions that check for patterns before or after a position without including them in the match. Positive lookahead (?=pattern) checks if pattern follows, negative lookahead (?!pattern) checks if pattern does not follow. Similarly, (?<=pattern) is positive lookbehind and (?<!pattern) is negative lookbehind.