Use this free online Java Regular Expression Tester to check whether your Java regex matches the text you expect. Enter your regular expression, provide the text to search through, and optionally specify a replacement string. You can also reference captured groups with $1, $2, and more, while escape sequences such as t, n, and r are supported.
After testing, you can review matching results or see how the replacement behaves using either Replace First or Replace All. Extra options let you enable flags such as Dotall, Multiline, Unix Lines, Canon EQ, Literal, Unicode Case, and Unicode Character Class to fine-tune how your expression is evaluated.
Key Features Of This Tool
- Perform Match, Replace First, or Replace All operations using your regular expression.
- Use captured groups such as
$1,$2, and special characters liket,n, andrin replacement strings. - Enable advanced regex options including Dotall, Multiline, Unix Lines, Canon EQ, Literal, Unicode Case, and Unicode Character Class modes.
- Highlights matched text in the test results, making it easier to identify successful matches.
- Copy your regular expression, input text, or results with a single click.
Regular Expression (Regex) Reference Guide
Regular expressions (Regex) are pattern-matching rules used to search, validate, extract, or replace text. Whether you’re checking email addresses, validating passwords, filtering data, or finding specific words, regular expressions provide a fast and flexible solution.
The table below explains the most commonly used regex symbols and what they represent.
| Regex Pattern | Description |
|---|---|
| Escapes special characters so they are treated as ordinary text. It is also used to introduce special sequences such as d, w, and s. |
^ | Matches the start of a string. Inside square brackets ([^...]), it means “exclude these characters.” |
$ | Matches the end of a string or line. |
* | Repeats the previous character or group zero or more times. |
+ | Requires the previous character or group to appear one or more times. |
? | Makes the previous item optional. When used after another quantifier, it performs the shortest possible match (lazy matching). |
. | Represents any single character except a newline in most regex engines. |
(pattern) | Groups expressions together and stores the matched value for later use (capturing group). |
(?:pattern) | Groups expressions without saving the matched value (non-capturing group). |
(?=pattern) | Positive lookahead. Ensures the following text matches without including it in the result. |
(?!pattern) | Negative lookahead. Ensures the following text does not match. |
x|y | Matches either the expression before or after the pipe symbol. |
{n} | Matches the preceding item exactly n times. |
{n,m} | Matches the preceding item between n and m times. |
{n,} | Matches the preceding item at least n times. |
{,m} | Matches the preceding item up to m times (supported in some regex flavors). |
[abc] | Matches any one character listed inside the brackets. |
[^abc] | Matches any character except those inside the brackets. |
[A-Z] | Matches any uppercase letter within the specified range. |
[0-9] | Matches any numeric digit from 0 through 9. |
b | Matches the boundary between a word character and a non-word character. |
B | Matches positions that are not word boundaries. |
[b] | Matches the backspace control character rather than a word boundary. |
d | Matches any decimal digit (0–9). |
D | Matches any character that is not a digit. |
w | Matches letters, digits, and the underscore character. |
W | Matches any character that is not a letter, digit, or underscore. |
s | Matches whitespace characters including spaces, tabs, and line breaks. |
S | Matches any character that is not whitespace. |
t | Matches a horizontal tab character. |
n | Matches a newline character. |
r | Matches a carriage return character. |
f | Matches a form feed character. |
v | Matches a vertical tab character. |
cX | Matches a control character, where X is a letter from A to Z. |
|