Skip to main content

Java Regex Tester

API reference

Test a Java (java.util.regex) regular expression against sample text — find(), matches() or lookingAt() results with match positions, capture groups, replaceAll output and a Pattern.compile snippet.

Input

The pattern as the regex engine sees it — single backslashes, like \d+, not the escaped Java string "\\d+".

Matcher.replaceAll syntax: $1 or ${name} insert a group, \ escapes the next character.

Output

Matches
#Matched Textstart()end()Capture Groups
No data yet
replaceAll result
Java
 
Was this helpful?

More ways to use this tool

REST API

curl -X POST https://api.iotools.cloud/v1/tool/java-regex-tester \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "pattern": "(?<user>\\w+)@(?<domain>[\\w.]+)",
    "mode": "find",
    "testString": "Contact: hello@example.com, support@iotools.clou…",
    "replacement": "${domain}:${user}"
  }'

Swap in your own key from your account. The tool's fields are the body — no wrapper.

Ask an AI agent

Use the IOTools `java-regex-tester` tool (Java Regex Tester) on this input:

YOUR_INPUT_HERE

Paste this at any agent connected to the IOTools MCP server, then add your input.

Embed widget

<iframe
  src="https://iotools.cloud/embed/java-regex-tester/"
  width="100%" height="520" frameborder="0" scrolling="no" loading="lazy"
  title="Java Regex Tester — iotools.cloud"
  sandbox="allow-scripts allow-forms allow-same-origin allow-downloads allow-popups allow-popups-to-escape-sandbox"
  allow="clipboard-write"
  style="width:100%;border:1px solid #e5e7eb;border-radius:12px;overflow:hidden"></iframe>
<script src="https://iotools.cloud/embed.js" async></script>

Drop this into your own page — free, no key required, just a link back.

Cost per API/MCP callFrom 5 credits
Need more credits?View pricing

Also available with

Guides

The Java Regex Tester runs a java.util.regex pattern against your text and shows what Java's Matcher would report: every match, its start() and end() offsets, and each capture group. It follows Java's dialect, not JavaScript's, so features such as possessive quantifiers (a++), atomic groups ((?>…)), \Q…\E quoting, POSIX classes like \p{Alpha} and class intersection ([a-z&&[^aeiou]]) behave the way they do in your Java code.

How to use it

  1. Type the pattern the way the regex engine sees it: \d+, not the Java string "\\d+".
  2. Pick the matcher method: find() lists every match, matches() checks that the whole text matches, lookingAt() checks that the text starts with a match.
  3. Tick any Pattern flags you use: CASE_INSENSITIVE, MULTILINE, DOTALL, COMMENTS or LITERAL.
  4. Paste your input text. Results update as you type.

Add a replacement such as ${user}@example.org or $2-$1 to preview replaceAll. A Pattern.compile(...) line with the pattern already escaped as a Java string literal is generated for you to paste into code.

Java details it reproduces

  • $ also matches just before a final line terminator, and ., ^ and $ use Java's line terminators (\n, \r\n, \r, \u0085, 
, 
).
  • Group names follow Java's rule: letters and digits only, starting with a letter.
  • Offsets are UTF-16 indices, the same as Java strings.

Limits

Inline flags such as (?i) work at the very start of the pattern only; use the checkboxes for the rest. \G, \X and Unicode blocks (\p{InGreek}) aren't supported. Case-insensitive matching uses Unicode case folding, where Java defaults to ASCII only. Patterns with a quantified group inside a quantifier, like (a+)+, are refused because they can hang; (a++)+ is fine.

Everything runs in your browser; nothing is uploaded.

For JavaScript patterns use the Regex Tester. To check a pattern for catastrophic backtracking use the Regex ReDoS Vulnerability Detector, and to escape strings for Java code use the Java & .NET String Escape tool.

java.util.regexpattern matcherpossessive quantifieratomic groupreplaceAlllookingAtposix class\p{Alpha}string literaljdk

Love the tools? Lose the ads.

One payment clears every ad from your account, for good. No subscription, no tracking.