---
title: "Regular Expressions Cheatsheet | FindUtils"
description: "JavaScript-style regex syntax, character classes, quantifiers, groups, assertions, flags, and example shape patterns."
url: https://findutils.com/cheatsheets/regex/
---

# Regular Expressions Cheatsheet

JavaScript-style regex syntax, character classes, quantifiers, groups, assertions, flags, and example shape patterns. 44 commands in 8 sections, filed under [Programming](https://findutils.com/cheatsheets/programming/).

## Character Classes

- `.`: Any character except newline
- `\d`: Any digit [0-9]
- `\D`: Any non-digit [^0-9]
- `\w`: Any word character [a-zA-Z0-9_]
- `\W`: Any non-word character
- `\s`: Any whitespace (space, tab, newline)
- `\S`: Any non-whitespace
- `[abc]`: Match a, b, or c
- `[^abc]`: Match anything except a, b, or c
- `[a-z]`: Match any lowercase letter
- `[0-9]`: Match any digit

## Quantifiers

- `*`: Zero or more times
- `+`: One or more times
- `?`: Zero or one time (optional)
- `{3}`: Exactly 3 times
- `{3,}`: 3 or more times
- `{3,5}`: Between 3 and 5 times
- `*?`: Zero or more (lazy/non-greedy)
- `+?`: One or more (lazy/non-greedy)

## Anchors & Boundaries

- `^`: Start of string (or line with m flag)
- `$`: End of string (or line with m flag)
- `\b`: Word boundary
- `\B`: Non-word boundary

## Groups & References

- `(abc)`: Capturing group
- `(?:abc)`: Non-capturing group
- `(?<name>abc)`: Named capturing group
- `\1`: Back-reference to group 1
- `(a|b)`: Match a or b (alternation)

## Lookahead & Lookbehind

- `(?=abc)`: Positive lookahead (followed by abc)
- `(?!abc)`: Negative lookahead (not followed by abc)
- `(?<=abc)`: Positive lookbehind (preceded by abc)
- `(?<!abc)`: Negative lookbehind (not preceded by abc)

## Flags

- `g`: Global search (find all matches)
- `i`: Case-insensitive search
- `m`: Multi-line mode (^ and $ match line boundaries)
- `s`: Dotall mode (. matches newlines)
- `u`: Unicode mode

## Common Patterns

- `^[\w.-]+@[\w.-]+\.\w{2,}$`: Email address (basic)
- `^https?://[\w.-]+(?:/\S*)?$`: URL (basic)
- `^\d{1,3}(\.\d{1,3}){3}$`: IPv4-shaped text only; also matches invalid values such as 999.999.999.999
- `^\d{4}-\d{2}-\d{2}$`: Date-shaped text only; also matches invalid values such as 2026-99-99
- `^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$`: Hex color code
- `^\+?\d{10,15}$`: Phone number (basic international)

## Sources

- `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions`: MDN JavaScript RegExp guide: syntax, assertions, flags, and engine-specific behavior.

## Related

- Cheatsheet: [Barcode Formats](https://findutils.com/cheatsheets/barcode-formats/)
- Cheatsheet: [JavaScript ES6+](https://findutils.com/cheatsheets/javascript-es6/)
- Cheatsheet: [Python Essentials](https://findutils.com/cheatsheets/python-essentials/)
- Guide: [Find and Replace Text Online: Free Tool with Regex Support](https://findutils.com/guides/text-find-replace-guide/)
- Guide: [Emoji Finder: Search Keywords, Copy Symbols and Check Variants](https://findutils.com/guides/emoji-finder-guide/)
- Tool: [Font Icon Search](https://findutils.com/design/font-icon-search/)
- Tool: [Regex Tester](https://findutils.com/developers/regex-tester/)
- Tool: [Text Find & Replace](https://findutils.com/text/text-find-replace/)
