Logo

Free Online Java Regular Expression Tester

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.

Java Regular Expression Tester Input
*You can use matched groups with $1, $2, etc. '\t', '\n', '\r' are also supported.
Results

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 like t, n, and r in 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 PatternDescription
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|yMatches 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.
bMatches the boundary between a word character and a non-word character.
BMatches positions that are not word boundaries.
[b]Matches the backspace control character rather than a word boundary.
dMatches any decimal digit (0–9).
DMatches any character that is not a digit.
wMatches letters, digits, and the underscore character.
WMatches any character that is not a letter, digit, or underscore.
sMatches whitespace characters including spaces, tabs, and line breaks.
SMatches any character that is not whitespace.
tMatches a horizontal tab character.
nMatches a newline character.
rMatches a carriage return character.
fMatches a form feed character.
vMatches a vertical tab character.
cXMatches a control character, where X is a letter from A to Z.
Matches the null character.
xhhMatches a character represented by a two-digit hexadecimal value.
uhhhhMatches a Unicode character represented by a four-digit hexadecimal value.
1, 2, etc.References text captured by an earlier capturing group. Useful for detecting repeated patterns.

Regex Flags

Regex flags modify how a pattern behaves during matching.

FlagPurpose
iIgnores letter casing, allowing uppercase and lowercase matches.
gFinds every occurrence instead of stopping after the first match.
mTreats each line as a separate string for ^ and $ anchors.
sAllows the dot (.) character to match newline characters.

Regular Expression Patterns

Below are some of the most frequently used regular expressions for validation, searching, and text processing.

Match an Email Address

Use this pattern to match the general format of an email address.

Pattern

^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,}$

Example Matches

  • user@example.com
  • john.doe@mail.co.uk

This pattern is suitable for most applications but does not guarantee that an email address actually exists.

Match an IPv4 Address

Validates the format of a standard IPv4 address.

Pattern

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

Example Match

192.168.1.100

Validate a Date (YYYY-MM-DD)

Checks whether a date follows the ISO format.

Pattern

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

Example Match

2026-06-27

This checks the format only. It does not verify whether the date is a real calendar date.

Match Integers

Positive integers only.

^d+$

Positive or negative integers.

^-?d+$

Match Decimal Numbers

Accepts whole numbers and decimals.

^-?d+(.d+)?$

Examples

  • 15
  • -25
  • 99.95

Match Hexadecimal Color Codes

Matches both 3-digit and 6-digit hex colors.

^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$

Examples

  • #FF6600
  • #FFF
  • 00CC99

Match Letters and Numbers Only

Useful for usernames and identifiers.

^[A-Za-z0-9]+$

Match URLs

Matches URLs beginning with HTTP or HTTPS.

^https?://.+$

Examples

  • http://example.com
  • https://example.com

Remove HTML Tags

Use this expression with the Replace feature and leave the replacement field empty.

<[^>]+>

Remove Empty Lines

Enable the Global (g) and Multiline (m) options.

Pattern

^s*r?n

Replacement

Leave empty.

Match Duplicate Consecutive Words

Finds repeated words such as “the the”.

b(w+)s+1b

Match Passwords (Minimum 8 Characters)

Requires at least one uppercase letter, one lowercase letter, one digit, and one special character.

^(?=.*[a-z])(?=.*[A-Z])(?=.*d)(?=.*[@$!%*?&]).{8,}$

Match Phone Numbers

Simple international phone number format.

^+?[1-9]d{7,14}$

Examples

  • +14155552671
  • 2348031234567

Helpful Tips

  • Start with simple patterns before creating complex expressions.
  • Use the g flag to find every occurrence in the text.
  • Use the i flag when letter case should be ignored.
  • Escape special characters such as ., (, ), [, and ? when matching them literally.
  • Test your regular expressions with several input examples to ensure they work as expected.

Related Tools