---
title: "Regex Cheatsheet | Codemo Tools - Utilities toolkit for Developers, QA, and Testers"
description: "Search and copy common regex patterns with examples for fast day-to-day use."
canonical_url: "https://codemotools.dev/cheatsheets/regex-cheatsheet"
meta:
  "og:description": "Search and copy common regex patterns with examples for fast day-to-day use."
  "og:image": "https://codemotools.dev/_og/d/c_Card.takumi%2Ctitle_Regex%2BCheatsheet%2Cdescription_Search%2Band%2Bcopy%2Bcommon%2Bregex%2Bpatterns%2Bwith%2Bexamples%2Bfor%2Bfast%2Bday-to-day%2Buse.%2Cp_Ii9jaGVhdHNoZWV0cy9yZWdleC1jaGVhdHNoZWV0Ig%2Cs_nr-pAmzp-3U8WxBO.png"
  "og:image:height": "600"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "Regex Cheatsheet | Codemo Tools - Utilities toolkit for Developers, QA, and Testers"
  "twitter:image": "https://codemotools.dev/_og/d/c_Card.takumi%2Ctitle_Regex%2BCheatsheet%2Cdescription_Search%2Band%2Bcopy%2Bcommon%2Bregex%2Bpatterns%2Bwith%2Bexamples%2Bfor%2Bfast%2Bday-to-day%2Buse.%2Cp_Ii9jaGVhdHNoZWV0cy9yZWdleC1jaGVhdHNoZWV0Ig%2Cs_nr-pAmzp-3U8WxBO.png"
---

> Index of every page on this site: [llms.txt](https://codemotools.dev/llms.txt)

**Cheat Sheets**

# **Regex Cheatsheet**

Search and copy practical regex snippets, grouped by category with quick examples.

**Search Regex Patterns**

### **Character Classes**

| Title | Description | Pattern | Example | Matched |
| --- | --- | --- | --- | --- |
| **Any digit** | Matches a single digit 0-9. | `\d` | Order 42 | 4 |
| **Any non-digit** | Matches non-digit runs. | `\D+` | ABC! 123 | ABC! |
| **Word character run** | Matches letters, digits, underscore. | `\w+` | user\_name1 and \_ok | user\_name1 |
| **Whitespace** | Matches spaces, tabs, newlines. | `\s+` | line one\\nline two | |

### **Anchors**

| Title | Description | Pattern | Example | Matched |
| --- | --- | --- | --- | --- |
| **Start of line** | Matches Hello at the start. | `^Hello` | Hello world | Hello |
| **End of line** | Matches world at the end. | `world$` | Hello world | world |

### **Quantifiers**

| Title | Description | Pattern | Example | Matched |
| --- | --- | --- | --- | --- |
| **Zero or more** | o appears zero or more times. | `go*gle` | ggle google gooogle | ggle, google, gooogle |
| **One or more** | o appears one or more times. | `go+gle` | ggle google gooogle | google, gooogle |
| **Optional** | u is optional. | `colou?r` | color colour | color, colour |
| **Exact range** | Matches numbers with length 2-4. | `\d{2,4}` | 7 42 512 10001 | 42, 512, 1000 |

### **Groups**

| Title | Description | Pattern | Example | Matched |
| --- | --- | --- | --- | --- |
| **Capturing group** | Captures repeated abc. | `(abc)+` | abcabc xyz | abcabc |
| **Non-capturing group** | Groups protocol variants without capturing. | `(?:https?)://\S+` | http://a.com https://b.dev | http://a.com, https://b.dev |
| **Named group** | Captures named parts. | `(?<year>\d{4})-(?<month>\d{2})` | 2026-05 release | 2026-05 |

### **Lookarounds**

| Title | Description | Pattern | Example | Matched |
| --- | --- | --- | --- | --- |
| **Positive lookahead** | Word before @ sign. | `\w+(?=@)` | hello@example.com | hello |
| **Negative lookahead** | foo not followed by bar. | `foo(?!bar)` | foo foobar fooz | foo, foo |
| **Positive lookbehind** | Numbers after dollar sign. | `(?<=\$)\d+` | $25 and $300 | 25, 300 |
| **Negative lookbehind** | Numbers not preceded by -. | `(?<!-)\d+` | -10 20 -3 7 | 0, 20, 7 |

### **Flags**

| Title | Description | Pattern | Example | Matched |
| --- | --- | --- | --- | --- |
| **Global flag** | Finds all lowercase cat matches. | `/cat/g` | cat CAT cat | cat, cat |
| **Ignore case flag** | Matches cat in any case (first match). | `/cat/i` | CAT cat cAt | CAT |
| **Multiline flag** | ^ applies per line. | `/^error/m` | info\\nerror\\nwarn | error |
| **Dotall flag** | Dot can match newlines. | `/a.b/s` | a\\nb | a\\nb |
| **Unicode flag** | Unicode letter matching. | `/\p{L}+/u` | naïve café | naïve, café |
| **Sticky flag** | Matches from current index only. | `/\d+/y` | 123-45 | 123 |

### **Escape Sequences**

| Title | Description | Pattern | Example | Matched |
| --- | --- | --- | --- | --- |
| **Newline** | Matches a line break character. | `\n` | line1\\nline2 | \\n |
| **Tab** | Matches a tab character. | `\t` | A\\tB | \\t |
| **Word boundary** | Matches cat as a full word. | `\bcat\b` | cat scatter catalog | cat |
| **Literal dot** | Matches an actual . character. | `\.` | v1.2.3 | ., . |
| **Literal backslash** | Matches \\ in text. | `\\` | C:\\\\\\\\Tools\\\\\\\\Regex | \\\\, \\\\, \\\\, \\\\ |

### **Common Patterns**

| Title | Description | Pattern | Example | Matched |
| --- | --- | --- | --- | --- |
| **Email** | Basic email matcher. | `\b[\w.%+-]+@[\w.-]+\.[A-Za-z]{2,}\b` | hello@example.com | hello@example.com |
| **URL (http/https)** | Matches web URLs. | `https?:\/\/[^\s]+` | https://google.com | https://google.com |
| **Hex color** | Matches 3 or 6-char hex colors. | `#(?:[0-9a-fA-F]{3}){1,2}\b` | #0ea5e9 | #0ea5e9 |
| **IPv4** | Matches IPv4 addresses. | `\b(?:25[0-5]\|2[0-4]\d\|1?\d?\d)(?:\.(?:25[0-5]\|2[0-4]\d\|1?\d?\d)){3}\b` | 192.168.1.10 | 192.168.1.10 |
| **Date (YYYY-MM-DD)** | Matches ISO-like calendar dates. | `\b\d{4}-\d{2}-\d{2}\b` | 2026-05-28 | 2026-05-28 |

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://codemotools.dev/#website","@type":"WebSite","description":"Free utilities for developers, QA, and testers. Access fast generators, converters, cheat sheets, and essential tools for daily use","name":"Codemo Tools - Utilities toolkit for Developers, QA, and Testers","url":"https://codemotools.dev/","publisher":{"@id":"https://codemotools.dev/#identity"}},{"@id":"https://codemotools.dev/cheatsheets/regex-cheatsheet#webpage","@type":"WebPage","description":"Search and copy common regex patterns with examples for fast day-to-day use.","name":"Regex Cheatsheet","url":"https://codemotools.dev/cheatsheets/regex-cheatsheet","isPartOf":{"@id":"https://codemotools.dev/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://codemotools.dev/cheatsheets/regex-cheatsheet"]}]},{"@id":"https://codemotools.dev/#identity","description":"A collection of essential and free online tools for developers and QA engineers","email":"contact@codemo.dev","name":"codemo","url":"https://codemotools.dev","@type":["Organization","Person"],"address":{"@type":"PostalAddress","addressLocality":"Ho Chi Minh City","addressCountry":"Vietnam"},"knowsAbout":["Free tools","Development tools","Quality Assurance tools","Cheat sheets","Generators","Converters","Online tools"],"sameAs":["https://linkedin.com/in/phatdangg","https://codemo.dev","https://tools.codemo.dev"]}]}
```

## Sitemap

See the full [sitemap](https://codemotools.dev/sitemap.md) for all pages.
