Applies to: General regular-expression concepts; exact syntax varies by engine Last reviewed: 2026-07-18
Regular expressions describe text patterns for searching, validation, extraction, and replacement. Engines differ significantly, so confirm whether the tool uses POSIX basic, POSIX extended, PCRE, JavaScript, Python, .NET, RE2, or another syntax.
| Pattern | Meaning |
|---|---|
abc |
Literal text |
. |
Any character except newline in many default modes |
^ |
Start of string or line |
$ |
End of string or line |
[abc] |
One character from the set |
[^abc] |
One character not in the set |
[a-z] |
Character range |
* |
Zero or more repetitions |
+ |
One or more repetitions |
? |
Zero or one repetition |
{n} |
Exactly n repetitions |
{n,m} |
Between n and m repetitions |
(...) |
Capturing group in many engines |
(?:...) |
Noncapturing group where supported |
| `a | b` |
\ |
Escape the next metacharacter |
These are common in Perl-compatible engines but are not portable to every tool:
| Pattern | Typical meaning |
|---|---|
\d |
Digit |
\D |
Nondigit |
\w |
Word character |
\W |
Nonword character |
\s |
Whitespace |
\S |
Nonwhitespace |
POSIX tools may prefer classes such as [[:digit:]], [[:alnum:]], and [[:space:]].
Quantifiers are greedy by default in many engines:
.*
Lazy forms such as .*? are supported by many PCRE-style engines but not by traditional POSIX grep, sed, or awk regular expressions.
Where supported:
| Pattern | Meaning |
|---|---|
(?=...) |
Positive lookahead |
(?!...) |
Negative lookahead |
(?<=...) |
Positive lookbehind |
(?<!...) |
Negative lookbehind |
RE2-based tools and some other engines intentionally do not support lookaround or backreferences.
Basic IPv4-shaped text, without validating numeric ranges:
\b[0-9]{1,3}(?:\.[0-9]{1,3}){3}\bSimple key-value line:
^([A-Za-z_][A-Za-z0-9_]*)=(.*)$Whitespace-only line:
^[[:space:]]*$- Avoid presenting a short regex as complete email, URL, IP, or security validation unless it truly implements the required grammar.
- Anchor validation patterns with
^and$or engine-specific full-match functions. - Escape untrusted input before inserting it into a generated pattern.
- Be aware of catastrophic backtracking in engines that use backtracking evaluation.
- Prefer parsing libraries for structured formats and protocol identifiers.
- Test normal, boundary, malformed, and adversarial inputs.
When a pattern behaves differently than expected, verify:
- the regex engine;
- basic versus extended mode;
- shell quoting;
- multiline and dot-all flags;
- Unicode and locale behavior;
- whether the API searches, matches from the start, or requires a full match.