Java Regex Tutorial: All Regular Expression Articles

All Java regex tutorials on howtodoinjava.com, grouped by topic: regex basics, input validation, and Unicode, symbols and text cleanup.

Java regex

A regular expression (regex) is a pattern that describes a set of strings, such as “five digits” or “a word that starts with cat“. In Java, the java.util.regex package compiles such a pattern into a Pattern object, and a Matcher object applies it to text. We use regex to validate input, find text, extract parts of it and replace it.

This page lists every Java regex tutorial on this site, grouped by topic. Each article starts with a quick-reference snippet, explains its patterns part by part, and has a runnable project with tests on GitHub, built with Java 25. Readers who are new to regex can start with the introduction to Java regular expressions.

The core Java regex calls fit in a few lines:

// 1. Whole input must match
"12345".matches("\\d{5}");                         // true

// 2. Compile once, reuse
Pattern word = Pattern.compile("\\bcat\\b");
word.matcher("the cat sat").find();                 // true

// 3. Extract every match
Pattern.compile("\\d+").matcher("a1 b22 c333")
    .results().map(MatchResult::group).toList();  // [1, 22, 333]

// 4. Replace
"a  b   c".replaceAll("\\s+", " ");                  // "a b c"

1. Regex Basics in Java

These articles explain the building blocks of every pattern. Reading them in order gives a solid base for the validation articles.

2. Validating Input With Regex

Each article gives a tested regex, explains it part by part, and says what the regex cannot check and which Java code covers the rest.

3. Unicode, Symbols and Text Cleanup

These articles cover characters beyond plain ASCII, which Java regex handles through Unicode properties such as \p{L} and \p{Sc}.

4. Conclusion

For a structured path, we read the basics group first, then pick the validation articles we need. The Unicode group helps when input comes from users in many languages.

5. References

The JavaDoc of the java.util.regex package is the full reference for the syntax and flags used in these tutorials.

Happy Learning !!

Source Code on Github

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.