Common

Input/Output

Reflection

RegExpUtils Tutorial

The RegExpUtils class provides methods for matching strings against regular expressions, extracting matched groups, and finding all matches in a string. These methods can be used for validating input, parsing text, and more.

Methods

1. isMatch(Pattern pattern, String str)

Checks if a string matches a given regular expression pattern.

Example:

Pattern pattern = Pattern.compile("^a");
boolean matches = RegExpUtils.isMatch(pattern, "abc");
// matches will be true

2. regMatch(String regexp, String str, int groupIndex)

Finds a match in a string using a regular expression and returns the specified group.

Example:

String match = RegExpUtils.regMatch("^a(b)", "abc", 1);
// match will be "b"

3. regMatch(String regexp, String str)

Finds a match in a string using a regular expression and returns the first group.

Example:

String match = RegExpUtils.regMatch("^a", "abc");
// match will be "a"

4. regMatchAll(String regexp, String str)

Finds all matches in a string using a regular expression and returns them as an array.

Example:

String[] matches = RegExpUtils.regMatchAll("\\d+", "abc123def456");
// matches will be ["123", "456"]