BackendBench
Coffee
Free tool

Regex tester for Java developers

Try a pattern against sample text, see every match and group, then copy it as a Java string with the backslashes already doubled.

#MatchAtGroups

As a Java string

Use with Pattern.compile(...)

Java regex, in short

Java's java.util.regex package is close to the syntax used in JavaScript, Python and Perl, so a pattern you test here will usually work unchanged. The two big practical differences are escaping, because the pattern lives inside a string literal, and a handful of features that exist in only one engine, which the tester calls out.

Common Java snippets: Pattern.compile("...") to build, matcher.find() to loop over matches, matcher.group(1) for a capture group, and String.matches(...) for a whole-string check.

Frequently asked questions

Why do I need to double the backslashes in Java?

A Java string literal treats \ as an escape character, so the regex \d+ must be written "\\d+". The tool prints the correctly escaped literal for you.

Is this the Java regex engine?

No. It uses the JavaScript engine in your browser, which shares most syntax with Java. The notes below the tester flag constructs that differ, such as inline flags and possessive quantifiers.

How do I use named groups in Java?

Write (?<year>\d{4}) and read it with matcher.group("year"). Java names may contain only letters and digits.

What is the difference between matches() and find()?

matches() requires the whole string to match; find() looks for a match anywhere. This tester behaves like find().

More tools you might need