Flags
| Flag | Effect |
|---|---|
g | Find all matches, not just the first |
i | Case-insensitive |
m | ^ and $ match at line breaks |
s | . also matches newlines |
u | Unicode mode (code points, \p{…}) |
y | Sticky: match only at lastIndex |
d | Record match indices |
Useful patterns
| Purpose | Pattern |
|---|---|
| Integer | ^-?\d+$ |
| Decimal number | ^-?\d+(\.\d+)?$ |
| Hex color | ^#?([0-9a-f]{3}|[0-9a-f]{6})$ (i) |
| ISO date | ^\d{4}-\d{2}-\d{2}$ |
| IPv4 (loose) | ^(\d{1,3}\.){3}\d{1,3}$ |
| Slug | ^[a-z0-9]+(-[a-z0-9]+)*$ |
| Whitespace runs | \s+ |
More syntax in the regex cheat sheet.
This tester uses your browser's JavaScript engine. PCRE (PHP), Python re and Java differ in details such as lookbehind support and named-group syntax.