---
title: "Regex Cheatsheet - Metacharacters and Patterns - AllTools"
description: "AllTools Regex Cheatsheet lists metacharacter meanings alongside email, phone and URL patterns, each with a worked example for form validation."
canonical_url: "https://tool.warmday.wang/en/info/regex-cheatsheet"
meta:
  author: AllTools
  keywords: "online tools, AllTools, free online tools, developer tools, image tools, PDF tools, text tools, unit converter, no login, browser-based tools"
  "og:description": "AllTools Regex Cheatsheet lists metacharacter meanings alongside email, phone and URL patterns, each with a worked example for form validation."
  "og:image": "https://tool.warmday.wang/img/og-cover.png"
  "og:image:alt": "AllTools Logo"
  "og:image:height": "630"
  "og:image:width": "1200"
  "og:title": "Regex Cheatsheet - Metacharacters and Patterns"
  "twitter:image": "https://tool.warmday.wang/img/og-cover.png"
---

> Index of every page on this site: [llms.txt](https://tool.warmday.wang/llms.txt)

# **Regex Cheatsheet**

Regular expression syntax cheatsheet, common patterns reference.

### **Basic Syntax**

`.`

Match any single character (except newline)

/a.c/ → "abc", "a1c"

`\`

Escape special characters

/a\\.c/ → "a.c"

`|`

Or (alternation)

/cat

`()`

Capturing group

/(ab)+/ → "abab"

`(?:)`

Non-capturing group

/(?:ab)+/ → "abab" (non-capturing)

`[...]`

Character set, match any one of them

/\[aeiou]/ → matches vowels

`[^...]`

Negated character set

/\[^0-9]/ → matches non-digits

`[a-z]`

Character range

/\[a-zA-Z]/ → matches letters

### **Quantifiers**

`*`

Match the preceding expression 0 or more times

/ab\*c/ → "ac", "abc", "abbc"

`+`

Match the preceding expression 1 or more times

/ab+c/ → "abc", "abbc"

`?`

Match the preceding expression 0 or 1 time

/ab?c/ → "ac", "abc"

`{n}`

Match the preceding expression exactly n times

/a{3}/ → "aaa"

`{n,}`

Match the preceding expression at least n times

/a{2,}/ → "aa", "aaa"

`{n,m}`

Match the preceding expression n to m times

/a{2,4}/ → "aa", "aaa", "aaaa"

`*?`

Non-greedy (lazy) version of \*

/a.\*?b/ → shortest match

`+?`

Non-greedy (lazy) version of +

/a.+?b/ → shortest match

`??`

Non-greedy (lazy) version of ?

/a??b/ → prefers not to match a

### **Anchors**

`^`

Match the beginning of a string

/^Hello/ → starts with Hello

`$`

Match the end of a string

/world$/ → ends with world

`\b`

Match a word boundary

/\\bcat\\b/ → "cat" not in "catch"

`\B`

Match a non-word boundary

/\\Bcat\\B/ → cat in "catch"

### **Character Classes**

`\d`

Match digits \[0-9]

/\\d+/ → "123"

`\D`

Match non-digits \[^0-9]

/\\D+/ → "abc"

`\w`

Match word characters \[a-zA-Z0-9\_]

/\\w+/ → "hello\_1"

`\W`

Match non-word characters

/\\W+/ → "!@#"

`\s`

Match whitespace (space, tab, etc.)

/\\s+/ → " "

`\S`

Match non-whitespace characters

/\\S+/ → "hello"

`\n`

Match newline character

/\\n/ → newline

`\t`

Match tab character

/\\t/ → Tab

`\0`

Match NULL character

/\\0/ → NULL

### **Assertions**

`(?=...)`

Positive lookahead assertion

/\\d(?=px)/ → the 2 in "2px"

`(?!...)`

Negative lookahead assertion

/\\d(?!px)/ → the 2 in "2em"

`(?<=...)`

Positive lookbehind assertion

/(?<=\\$)\\d+/ → the 100 in "$100"

`(?<!...)`

Negative lookbehind assertion

/(?\<!\\$)\\d+/ → the 100 in "100"

### **Modifiers (Flags)**

| **Flag** | **Name** | **Description** |
| --- | --- | --- |
| g | global | Global search, find all matches |
| i | ignoreCase | Case-insensitive |
| m | multiline | Multiline mode, ^ and $ match start/end of line |
| s | dotAll | Make . match all characters including newlines |
| u | unicode | Unicode mode, handle Unicode characters correctly |
| y | sticky | Sticky match, only start from lastIndex position |

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://tool.warmday.wang/#organization","name":"AllTools","alternateName":"AllTools - 全能工具箱","url":"https://tool.warmday.wang/","logo":{"@type":"ImageObject","url":"https://tool.warmday.wang/img/logo.png","width":512,"height":512}},{"@type":"WebSite","@id":"https://tool.warmday.wang/en#website","url":"https://tool.warmday.wang/en","name":"AllTools","inLanguage":"en","publisher":{"@id":"https://tool.warmday.wang/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://tool.warmday.wang/en?q={search_term_string}"},"query-input":"required name=search_term_string"}},{"@type":"WebPage","@id":"https://tool.warmday.wang/en/info/regex-cheatsheet#webpage","url":"https://tool.warmday.wang/en/info/regex-cheatsheet","isPartOf":{"@id":"https://tool.warmday.wang/en#website"},"inLanguage":"en","name":"Regex Cheatsheet - Metacharacters and Patterns","description":"AllTools Regex Cheatsheet lists metacharacter meanings alongside email, phone and URL patterns, each with a worked example for form validation."},{"@type":"BreadcrumbList","@id":"https://tool.warmday.wang/en/info/regex-cheatsheet#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://tool.warmday.wang/en"},{"@type":"ListItem","position":2,"name":"Reference","item":"https://tool.warmday.wang/en/info"},{"@type":"ListItem","position":3,"name":"Regex Cheatsheet","item":"https://tool.warmday.wang/en/info/regex-cheatsheet"}]}]}
```

## Sitemap

See the full [sitemap](https://tool.warmday.wang/sitemap.md) for all pages.
