⚡
usefultools.dev
.*

Regex Cheatsheet

NOVO

Regex cheatsheet covering anchors, classes, quantifiers, groups, lookaround, flags and ready patterns, with JavaScript notes. Searchable, with one-click copy.

Funciona 100% no seu navegador — o que você insere nunca é enviado nem armazenado nos nossos servidores.

Esta ferramenta ainda não está totalmente traduzida, por isso parte do texto continua em inglês. A ferramenta funciona da mesma forma em todos os idiomas.

79 entradas em 9 seções

Anchors & boundaries

  • ^

    Start of the string (start of each line with the m flag).

  • $

    End of the string (end of each line with the m flag).

  • \b

    Word boundary: between a word character and a non-word character.

  • \B

    Not a word boundary.

  • \A

    Start of the whole string. Not in JavaScript; use ^ without the m flag.

  • \z

    End of the whole string. Not in JavaScript; use $ without the m flag.

Character classes

  • .

    Any character except a line break (with the s flag, including line breaks).

  • \d

    A digit, same as [0-9] in most flavors.

  • \D

    Any character that is not a digit.

  • \w

    A word character: letter, digit or underscore (ASCII only in JavaScript).

  • \W

    Any character that is not a word character.

  • \s

    Whitespace: space, tab, line break and similar.

  • \S

    Any character that is not whitespace.

  • [abc]

    One of the listed characters: a, b or c.

  • [^abc]

    Any character except a, b and c.

  • [a-z]

    One character in a range, here lowercase a to z.

  • [a-zA-Z0-9]

    Several ranges in one class: ASCII letters and digits.

  • [\s\S]

    Any character including line breaks, a trick that works without the s flag.

Quantifiers

A quantifier applies to the item right before it.

  • *

    Zero or more times (greedy).

  • +

    One or more times (greedy).

  • ?

    Zero or one time: makes the item optional.

  • {3}

    Exactly 3 times.

  • {2,}

    2 or more times.

  • {2,5}

    Between 2 and 5 times.

  • *?

    Lazy: zero or more times, as few as possible.

  • +?

    Lazy: one or more times, as few as possible.

  • {2,5}?

    Lazy range: as few repetitions as possible within 2 to 5.

  • a++

    Possessive quantifier: no backtracking. Supported in PCRE, Java and others, not in JavaScript.

Groups & backreferences

  • (abc)

    Capturing group: groups the pattern and remembers the match.

  • (?:abc)

    Non-capturing group: groups without remembering.

  • a|b

    Alternation: match a or b.

  • (cat|dog)s?

    Group an alternation, then make the "s" optional.

  • \1

    Backreference: the same text matched by capturing group 1.

  • (\w)\1

    Two identical word characters in a row, such as "ll".

  • (?<year>\d{4})

    Named capturing group (JavaScript, .NET, PCRE).

  • \k<year>

    Backreference to a named group in JavaScript.

  • (?P<year>\d{4})

    Named group syntax used by Python (and PCRE).

Lookaround

Lookarounds check the surroundings without including them in the match.

  • a(?=b)

    Positive lookahead: "a" only when followed by "b".

  • a(?!b)

    Negative lookahead: "a" only when not followed by "b".

  • (?<=\$)\d+

    Positive lookbehind: digits that come right after a $ sign.

  • (?<!\$)\b\d+

    Negative lookbehind: digits not preceded by a $ sign.

  • ^(?=.*\d)(?=.*[a-z]).{8,}$

    Password-style check: at least 8 characters with a digit and a lowercase letter.

Flags

Written after the closing slash in JavaScript, e.g. /abc/gi.

  • g

    Global: find all matches instead of stopping at the first.

  • i

    Ignore case.

  • m

    Multiline: ^ and $ match at each line.

  • s

    Dot-all: . also matches line breaks.

  • u

    Unicode: treat the pattern as code points and enable \p{...}.

  • y

    Sticky (JavaScript): match only at lastIndex.

  • d

    Indices (JavaScript): add start and end positions of each group to the result.

  • (?i)

    Inline flag at the start of a pattern, used in Python, PCRE and Java. JavaScript does not support it.

Escapes & special characters

These characters have a special meaning and need a backslash to match literally: \ ^ $ . | ? * + ( ) [ ] { }

  • \.

    A literal dot.

  • \\

    A literal backslash.

  • \/

    A literal slash (needed inside /.../ literals in JavaScript).

  • \n

    Line feed (new line).

  • \r

    Carriage return.

  • \t

    Tab.

  • \x41

    A character by its two-digit hex code, here "A".

  • \u00e9

    A character by its four-digit Unicode code, here "é".

  • \p{L}

    Any Unicode letter (needs the u flag in JavaScript).

  • \p{Lu}

    Any uppercase Unicode letter (needs the u flag in JavaScript).

Common patterns

Starting points, not full validators. Always test with your own data.

  • ^[^\s@]+@[^\s@]+\.[^\s@]+$

    Email, loose check: [email protected]. The full email standard is far wider, so confirm by sending a message.

  • https?:\/\/[^\s/$.?#].[^\s]*

    Web URL with http or https, simple version. Misses other schemes and some valid edge cases.

  • ^(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)$

    IPv4 address with each part from 0 to 255. Does not say whether the address is reachable.

  • ^\d{4}-\d{2}-\d{2}$

    Date shaped like 2026-11-23. Checks the layout only, so 2026-99-99 also passes.

  • ^([01]\d|2[0-3]):[0-5]\d$

    Time in 24-hour HH:MM format.

  • ^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$

    Hex color such as #fff or #1a2b3c, with optional #.

  • ^[a-z0-9]+(?:-[a-z0-9]+)*$

    URL slug: lowercase words joined by single hyphens.

  • ^\+?[0-9\s().-]{7,15}$

    Loose phone number check. Phone formats differ by country, so treat it as a rough filter.

  • ^\s+|\s+$

    Leading and trailing whitespace, handy for trimming with a replace.

  • \s{2,}

    Two or more whitespace characters in a row, to collapse into a single space.

JavaScript notes

  • /pattern/flags

    Regex literal syntax. Same as new RegExp("pattern", "flags").

  • regex.test(str)

    Returns true or false. With g or y, it moves lastIndex between calls.

  • str.match(regex)

    First match with groups, or all matches as an array when g is set.

  • str.matchAll(/(\d+)/g)

    Iterator of every match including groups. The regex must have the g flag.

  • str.replace(/(\w+) (\w+)/, "$2 $1")

    Replace using $1, $2 for capture groups, here swapping two words.

  • str.replaceAll(/a/g, "b")

    Replace every match. A regex argument must have the g flag.

  • const { groups } = /(?<y>\d{4})-(?<m>\d{2})/.exec(str)

    Read named groups from the groups object: groups.y and groups.m.

  • str.replace(re, "$<y>")

    Use a named group in a replacement string.

  • new RegExp(escapedText, "g")

    Build a pattern from a string. Escape user text first, since it may contain special characters.

⚡

Exemplos rápidos

Entradas típicas e os resultados que esta ferramenta gera.

Class
Any Unicode letter (u flag)
\p{L}
Lookbehind
Digits after a $ sign
(?<=\$)\d+
Pattern
Date shaped like 2026-11-23
^\d{4}-\d{2}-\d{2}$
Group
Named group for a year
(?<year>\d{4})
📖

Visão geral

Regular expressions describe text patterns in a compact syntax that is easy to forget. This regex cheatsheet covers anchors, character classes, quantifiers, groups and backreferences, lookaround, flags and escapes, plus starting patterns for email, URL, IPv4 address, date and time.

Syntax differs a little between flavors, so entries say where JavaScript, Python or PCRE behave differently, and a JavaScript section covers named groups, matchAll and the sticky and unicode flags. The common patterns are starting points with honest caveats, not complete validators.

Filter the list, copy a pattern, then try it on your own text in the Regex Tester. Everything stays in your browser.

Por que usar esta ferramenta?

  • Look up regex syntax without leaving the page
  • Notes on JavaScript versus Python differences
  • Common patterns with honest limits
  • Filter by symbol or keyword
  • Copy any pattern with one click
⭐

Recursos

⚓

Anchors and classes

Boundaries, digits, word characters, ranges and negated sets.

🔁

Quantifiers

Greedy, lazy and possessive repetition with the flavors that support each.

👀

Lookaround

Lookahead and lookbehind examples, including a password-style check.

🧪

Common patterns

Email, URL, IPv4, date, time, hex color and slug, each with a caveat.

🟨

JavaScript notes

test, match, matchAll, replaceAll and named groups in code.

📋

Copy per pattern

Each row has a Copy button for the exact text.

🛠️

Como usar

1

Pick a section

Scroll to Quantifiers, Lookaround, Flags or any other group.

2

Or filter

Type a symbol or word such as "lazy" or "email" in the filter box.

3

Read the note

Check the description for flavor differences before you copy.

4

Test it

Press Copy, then paste the pattern into the Regex Tester with your own text.

🤔

Perguntas frequentes