Home AI Tool Reviews About
Free Tool

Regex Cheat Sheet

Free online regex cheat sheet. No sign-up, no installation. Runs entirely in your browser.

What is a Regular Expression?

A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. It's used to match, find, and replace text in strings. Regular expressions are powerful tools in programming and text processing, supported by nearly every programming language including JavaScript, Python, PHP, Java, C#, and Ruby.

This cheat sheet provides quick access to the most common regex patterns and syntax, complete with working examples you can test right in your browser. Whether you're validating email addresses, extracting data, or performing complex text replacements, regex is an essential skill for any developer.

How to Use This Cheat Sheet

1. Browse by Category: Select a category from the dropdown to filter regex syntax by type (character classes, anchors, quantifiers, etc).

2. Click an Entry: Click on any regex pattern to load it into the interactive tester below.

3. Test with Your Text: Enter any text in the test area and the results update automatically. See all matches highlighted with count.

4. Copy Patterns: Click the "Copy" button next to any pattern to add it to your clipboard for use in your code.

Common Regex Use Cases

Email Validation: Verify that a string is a valid email address format before storing or processing.

URL Matching: Extract or validate URLs from text content, log files, or user input.

Phone Numbers: Match phone numbers in various formats (with or without dashes, parentheses, country codes).

Password Strength: Ensure passwords meet specific complexity requirements (uppercase, lowercase, numbers, special characters).

Data Extraction: Pull specific information from log files, HTML content, CSV data, or other structured text formats.

Text Replacement: Find and replace patterns across large documents efficiently using regex-powered find-and-replace.

Frequently Asked Questions

What's the difference between greedy and lazy quantifiers?

Greedy quantifiers (*, +, {n,m}) match as much as possible, while lazy quantifiers add a question mark (*?, +?) to match as little as possible. For example, with "hello world", h.*d matches the entire string, but h.*?d matches just "hello".

What does (?:...) mean?

The (?:...) syntax creates a non-capturing group. It groups characters for quantifiers or alternation without creating a numbered capture group. Non-capturing groups are more efficient when you only need grouping functionality, not result extraction.

How do I match special characters like dots or asterisks?

Special regex characters must be escaped with a backslash. Use \. for a literal dot, \* for an asterisk, and \+ for a plus sign. Common characters to escape: . * + ? ^ $ { } [ ] ( ) | \

What's the difference between \b and \B?

\b matches a word boundary (the position between a word character and a non-word character). \B matches a non-word boundary. For example, \bword\b matches "word" as a complete word but not inside "keywords".

Can I use multiple flags together?

Yes, you can combine flags when creating a regex. For example, new RegExp(pattern, 'gim') applies global, case-insensitive, and multiline flags simultaneously. This is useful for complex matching scenarios.

What's the difference between test() and match()?

test() returns a boolean (true/false) indicating whether a match exists. match() returns an array with all matches and captured groups. Use test() for yes/no checks and match() when you need the actual matched text.

Scroll to Top