Java : Matcher (regex) con ejemplos
Matcher (Java SE 22 & JDK 22) en Java con ejemplos.
Encontrará ejemplos de código en la mayoría de los métodos de Matcher.
Nota :
- Este artículo puede utilizar software de traducción para su comodidad. Consulte también la versión original en inglés.
Summary
final var pattern = Pattern.compile("a+bc");
final var matcher = pattern.matcher("abc 012 aaabc");
// First match.
System.out.println(matcher.find()); // true
System.out.println(matcher.start()); // 0
System.out.println(matcher.end()); // 3
System.out.println(matcher.group()); // "abc"
// Next match.
System.out.println(matcher.find()); // true
System.out.println(matcher.start()); // 8
System.out.println(matcher.end()); // 13
System.out.println(matcher.group()); // "aaabc"
// No match.
System.out.println(matcher.find()); // false
final var pattern = Pattern.compile("a+bc");
final var matcher = pattern.matcher("abc 012 aaabc");
final var stream = matcher.results();
stream.forEach(matchResult -> {
System.out.println("------");
System.out.println("start : " + matchResult.start());
System.out.println("end : " + matchResult.end());
System.out.println("group : " + matchResult.group());
});
// Result
// ↓
//------
//start : 0
//end : 3
//group : abc
//------
//start : 8
//end : 13
//group : aaabc
Methods
Matcher appendReplacement (StringBuffer sb, String replacement)
final var pattern = Pattern.compile("cat");
final var matcher = pattern.matcher("one cat two cats in the yard");
final var sb = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(sb, "dog");
}
System.out.println(sb); // "one dog two dog"
matcher.appendTail(sb);
System.out.println(sb); // "one dog two dogs in the yard"
Matcher appendReplacement (StringBuilder sb, String replacement)
final var pattern = Pattern.compile("cat");
final var matcher = pattern.matcher("one cat two cats in the yard");
final var sb = new StringBuilder();
while (matcher.find()) {
matcher.appendReplacement(sb, "dog");
}
System.out.println(sb); // "one dog two dog"
matcher.appendTail(sb);
System.out.println(sb); // "one dog two dogs in the yard"
StringBuffer appendTail (StringBuffer sb)
final var pattern = Pattern.compile("cat");
final var matcher = pattern.matcher("one cat two cats in the yard");
final var sb = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(sb, "dog");
}
System.out.println(sb); // "one dog two dog"
matcher.appendTail(sb);
System.out.println(sb); // "one dog two dogs in the yard"
StringBuilder appendTail (StringBuilder sb)
final var pattern = Pattern.compile("cat");
final var matcher = pattern.matcher("one cat two cats in the yard");
final var sb = new StringBuilder();
while (matcher.find()) {
matcher.appendReplacement(sb, "dog");
}
System.out.println(sb); // "one dog two dog"
matcher.appendTail(sb);
System.out.println(sb); // "one dog two dogs in the yard"
int end ()
final var pattern = Pattern.compile("a+bc");
final var input = "aaaaabc";
final var matcher = pattern.matcher(input);
System.out.println(matcher.matches()); // true
final var start = matcher.start();
System.out.println(start); // 0
final var end = matcher.end();
System.out.println(end); // 7
final var group = input.substring(start, end);
System.out.println(group); // "aaaaabc"
final var pattern = Pattern.compile("a+bc");
final var input = "012abcXYZ";
final var matcher = pattern.matcher(input);
System.out.println(matcher.find()); // true
final var start = matcher.start();
System.out.println(start); // 3
final var end = matcher.end();
System.out.println(end); // 6
final var group = input.substring(start, end);
System.out.println(group); // "abc"
int end (int group)
final var pattern = Pattern.compile("(abc|efg)_012_(x..)");
final var matcher = pattern.matcher("abc_012_xyz");
System.out.println(matcher.matches()); // true
System.out.println(matcher.start()); // 0
System.out.println(matcher.end()); // 11
System.out.println(matcher.group()); // "abc_012_xyz"
final var groupCount = matcher.groupCount();
System.out.println(groupCount); // 2
for (int i = 1; i <= groupCount; i++) {
System.out.println("------");
System.out.println("i : " + i);
System.out.println("start : " + matcher.start(i));
System.out.println("end : " + matcher.end(i));
System.out.println("group : " + matcher.group(i));
}
// Result
// ↓
//------
//i : 1
//start : 0
//end : 3
//group : abc
//------
//i : 2
//start : 8
//end : 11
//group : xyz
int end (String name)
final var pattern = Pattern.compile("(?<A>abc|efg)_012_(?<B>x..)");
final var matcher = pattern.matcher("abc_012_xyz");
System.out.println(matcher.matches()); // true
final var result = matcher.toMatchResult();
System.out.println(result.start()); // 0
System.out.println(result.end()); // 11
System.out.println(result.group()); // "abc_012_xyz"
{
final var name = "A";
System.out.println(matcher.start(name)); // 0
System.out.println(matcher.end(name)); // 3
System.out.println(matcher.group(name)); // "abc"
}
{
final var name = "B";
System.out.println(matcher.start(name)); // 8
System.out.println(matcher.end(name)); // 11
System.out.println(matcher.group(name)); // "xyz"
}
boolean find ()
final var pattern = Pattern.compile("a+bc");
final var matcher = pattern.matcher("abc 012 aaabc");
System.out.println(matcher.hasMatch()); // false
{
System.out.println(matcher.find()); // true
System.out.println(matcher.hasMatch()); // true
final var result = matcher.toMatchResult();
System.out.println(result.start()); // 0
System.out.println(result.end()); // 3
System.out.println(result.group()); // "abc"
}
{
System.out.println(matcher.find()); // true
System.out.println(matcher.hasMatch()); // true
final var result = matcher.toMatchResult();
System.out.println(result.start()); // 8
System.out.println(result.end()); // 13
System.out.println(result.group()); // "aaabc"
}
System.out.println(matcher.find()); // false
System.out.println(matcher.hasMatch()); // false
boolean find (int start)
final var pattern = Pattern.compile("a+bc");
final var matcher = pattern.matcher("012 abc xyz aaabc");
{
System.out.println(matcher.find(8)); // true
final var result = matcher.toMatchResult();
System.out.println(result.start()); // 12
System.out.println(result.end()); // 17
System.out.println(result.group()); // "aaabc"
}
{
System.out.println(matcher.find(1)); // true
final var result = matcher.toMatchResult();
System.out.println(result.start()); // 4
System.out.println(result.end()); // 7
System.out.println(result.group()); // "abc"
}
String group ()
final var pattern = Pattern.compile("a+bc");
final var matcher = pattern.matcher("abc 012 aaabc xyz");
System.out.println(matcher.find()); // true
System.out.println(matcher.group()); // "abc"
System.out.println(matcher.find()); // true
System.out.println(matcher.group()); // "aaabc"
System.out.println(matcher.find()); // false
String group (int group)
final var pattern = Pattern.compile("(abc|efg)_012_(x..)");
final var matcher = pattern.matcher("abc_012_xyz");
System.out.println(matcher.matches()); // true
System.out.println(matcher.start()); // 0
System.out.println(matcher.end()); // 11
System.out.println(matcher.group()); // "abc_012_xyz"
final var groupCount = matcher.groupCount();
System.out.println(groupCount); // 2
for (int i = 1; i <= groupCount; i++) {
System.out.println("------");
System.out.println("i : " + i);
System.out.println("start : " + matcher.start(i));
System.out.println("end : " + matcher.end(i));
System.out.println("group : " + matcher.group(i));
}
// Result
// ↓
//------
//i : 1
//start : 0
//end : 3
//group : abc
//------
//i : 2
//start : 8
//end : 11
//group : xyz
String group (String name)
final var pattern = Pattern.compile("(?<A>abc|efg)_012_(?<B>x..)");
final var matcher = pattern.matcher("abc_012_xyz");
System.out.println(matcher.matches()); // true
final var result = matcher.toMatchResult();
System.out.println(result.start()); // 0
System.out.println(result.end()); // 11
System.out.println(result.group()); // "abc_012_xyz"
{
final var name = "A";
System.out.println(matcher.start(name)); // 0
System.out.println(matcher.end(name)); // 3
System.out.println(matcher.group(name)); // "abc"
}
{
final var name = "B";
System.out.println(matcher.start(name)); // 8
System.out.println(matcher.end(name)); // 11
System.out.println(matcher.group(name)); // "xyz"
}
int groupCount ()
final var pattern = Pattern.compile("(abc|efg)_012_(x..)");
final var matcher = pattern.matcher("abc_012_xyz");
System.out.println(matcher.matches()); // true
System.out.println(matcher.start()); // 0
System.out.println(matcher.end()); // 11
System.out.println(matcher.group()); // "abc_012_xyz"
final var groupCount = matcher.groupCount();
System.out.println(groupCount); // 2
for (int i = 1; i <= groupCount; i++) {
System.out.println("------");
System.out.println("i : " + i);
System.out.println("start : " + matcher.start(i));
System.out.println("end : " + matcher.end(i));
System.out.println("group : " + matcher.group(i));
}
// Result
// ↓
//------
//i : 1
//start : 0
//end : 3
//group : abc
//------
//i : 2
//start : 8
//end : 11
//group : xyz
boolean hasAnchoringBounds ()
final var pattern = Pattern.compile("^abc xyz$");
final var input = "012 abc xyz";
{
final var matcher = pattern.matcher(input);
System.out.println(matcher.hasAnchoringBounds()); // true
// Sets the limits of this matcher's region.
System.out.println(input.substring(4, 11)); // "abc xyz"
matcher.region(4, 11);
System.out.println(matcher.find()); // true
final var result = matcher.toMatchResult();
System.out.println(result.start()); // 4
System.out.println(result.end()); // 11
System.out.println(result.group()); // "abc xyz"
}
{
final var matcher = pattern.matcher(input);
matcher.useAnchoringBounds(false);
System.out.println(matcher.hasAnchoringBounds()); // false
matcher.region(4, 11);
System.out.println(matcher.find()); // false
}
boolean hasMatch ()
final var pattern = Pattern.compile("a+bc");
final var matcher = pattern.matcher("abc 012 aaabc");
System.out.println(matcher.hasMatch()); // false
{
System.out.println(matcher.find()); // true
System.out.println(matcher.hasMatch()); // true
final var result = matcher.toMatchResult();
System.out.println(result.start()); // 0
System.out.println(result.end()); // 3
System.out.println(result.group()); // "abc"
}
{
System.out.println(matcher.find()); // true
System.out.println(matcher.hasMatch()); // true
final var result = matcher.toMatchResult();
System.out.println(result.start()); // 8
System.out.println(result.end()); // 13
System.out.println(result.group()); // "aaabc"
}
System.out.println(matcher.find()); // false
System.out.println(matcher.hasMatch()); // false
boolean hasTransparentBounds ()
final var pattern = Pattern.compile("\\by...");
final var input = "xyz12 yz34";
{
final var matcher = pattern.matcher(input);
System.out.println(matcher.hasTransparentBounds()); // false
// Sets the limits of this matcher's region.
System.out.println(input.substring(1, 10)); // "yz12 yz34"
matcher.region(1, 10);
System.out.println(matcher.find()); // true
final var result = matcher.toMatchResult();
System.out.println(result.group()); // "yz12"
}
{
final var matcher = pattern.matcher(input);
matcher.useTransparentBounds(true);
System.out.println(matcher.hasTransparentBounds()); // true
matcher.region(1, 10);
// This matcher to use transparent bounds.
System.out.println(matcher.find()); // true
final var result = matcher.toMatchResult();
System.out.println(result.group()); // "yz34"
}
boolean hitEnd ()
final var pattern = Pattern.compile("cat");
final var matcher = pattern.matcher("one cat two cats in the yard");
while (matcher.find()) {
System.out.println("-------");
System.out.println("hitEnd : " + matcher.hitEnd());
final var result = matcher.toMatchResult();
System.out.println("start : " + result.start());
System.out.println("end : " + result.end());
}
// Result
// ↓
//-------
//hitEnd : false
//start : 4
//end : 7
//-------
//hitEnd : false
//start : 12
//end : 15
System.out.println(matcher.hitEnd()); // true
boolean lookingAt ()
final var pattern = Pattern.compile("a+bc");
final var matcher = pattern.matcher("aaabc");
System.out.println(matcher.lookingAt()); // true
final var result = matcher.toMatchResult();
System.out.println(result.start()); // 0
System.out.println(result.end()); // 5
System.out.println(result.group()); // "aaabc"
final var pattern = Pattern.compile("a+bc");
final var matcher = pattern.matcher("abcXYZ");
System.out.println(matcher.lookingAt()); // true
final var result = matcher.toMatchResult();
System.out.println(result.start()); // 0
System.out.println(result.end()); // 3
System.out.println(result.group()); // "abc"
final var pattern = Pattern.compile("a+bc");
final var matcher = pattern.matcher("012abc");
System.out.println(matcher.lookingAt()); // false
boolean matches ()
final var pattern = Pattern.compile("a+bc");
final var matcher = pattern.matcher("abc");
System.out.println(matcher.matches()); // true
final var result = matcher.toMatchResult();
System.out.println(result.start()); // 0
System.out.println(result.end()); // 3
System.out.println(result.group()); // "abc"
final var pattern = Pattern.compile("a+bc");
final var matcher = pattern.matcher("aaaaabc");
System.out.println(matcher.matches()); // true
final var result = matcher.toMatchResult();
System.out.println(result.start()); // 0
System.out.println(result.end()); // 7
System.out.println(result.group()); // "aaaaabc"
final var pattern = Pattern.compile("a+bc");
final var matcher = pattern.matcher("012abc");
System.out.println(matcher.matches()); // false
final var pattern = Pattern.compile("a+bc");
final var matcher = pattern.matcher("abcZ");
System.out.println(matcher.matches()); // false
Map<String,Integer> namedGroups ()
final var pattern = Pattern.compile("(?<A>abc|efg)_012_(?<B>x..)");
final var matcher = pattern.matcher("abc_012_xyz");
System.out.println(matcher.matches()); // true
System.out.println("-- groups --");
for (final var entry : matcher.namedGroups().entrySet()) {
System.out.println("entry : " + entry);
final var num = entry.getValue();
System.out.println(" group : " + matcher.group(num));
}
// Result
// ↓
//true
//-- groups --
//entry : A=1
// group : abc
//entry : B=2
// group : xyz
Pattern pattern ()
final var pattern = Pattern.compile("a+bc");
final var matcher = pattern.matcher("aaabc");
System.out.println(matcher.pattern()); // "a+bc"
static String quoteReplacement (String s)
final var pattern = Pattern.compile(" ");
final var matcher = pattern.matcher("abc 012 xyz");
final var replacement = Matcher.quoteReplacement("$");
System.out.println(replacement); // "\$"
final var ret = matcher.replaceAll(replacement);
System.out.println(ret); // "abc$012$xyz"
Matcher region (int start, int end)
final var pattern = Pattern.compile("a+bc+");
final var input = "aaabccc";
final var matcher = pattern.matcher(input);
System.out.println(input.substring(2, 6)); // "abcc"
matcher.region(2, 6);
System.out.println(matcher.regionStart()); // 2
System.out.println(matcher.regionEnd()); // 6
System.out.println(matcher.matches()); // true
final var result = matcher.toMatchResult();
System.out.println(result.group()); // "abcc"
// An example without the region method.
final var pattern = Pattern.compile("a+bc+");
final var matcher = pattern.matcher("aaabccc");
System.out.println(matcher.matches()); // true
final var result = matcher.toMatchResult();
System.out.println(result.group()); // "aaabccc"
int regionEnd ()
final var pattern = Pattern.compile("a+bc+");
final var input = "aaabccc";
final var matcher = pattern.matcher(input);
System.out.println(input.substring(2, 6)); // "abcc"
matcher.region(2, 6);
System.out.println(matcher.regionStart()); // 2
System.out.println(matcher.regionEnd()); // 6
System.out.println(matcher.matches()); // true
final var result = matcher.toMatchResult();
System.out.println(result.group()); // "abcc"
// An example without the region method.
final var pattern = Pattern.compile("a+bc+");
final var matcher = pattern.matcher("aaabccc");
System.out.println(matcher.matches()); // true
final var result = matcher.toMatchResult();
System.out.println(result.group()); // "aaabccc"
int regionStart ()
final var pattern = Pattern.compile("a+bc+");
final var input = "aaabccc";
final var matcher = pattern.matcher(input);
System.out.println(input.substring(2, 6)); // "abcc"
matcher.region(2, 6);
System.out.println(matcher.regionStart()); // 2
System.out.println(matcher.regionEnd()); // 6
System.out.println(matcher.matches()); // true
final var result = matcher.toMatchResult();
System.out.println(result.group()); // "abcc"
// An example without the region method.
final var pattern = Pattern.compile("a+bc+");
final var matcher = pattern.matcher("aaabccc");
System.out.println(matcher.matches()); // true
final var result = matcher.toMatchResult();
System.out.println(result.group()); // "aaabccc"
String replaceAll (String replacement)
final var pattern = Pattern.compile("a*b");
final var matcher = pattern.matcher("aabfooaabfooabfoob");
final var result = matcher.replaceAll("-");
System.out.println(result); // "-foo-foo-foo-"
String replaceAll (Function<MatchResult,String> replacer)
final var pattern = Pattern.compile("dog");
final var matcher = pattern.matcher("zzzdogzzzdogzzz");
final var result = matcher.replaceAll(mr -> mr.group().toUpperCase());
System.out.println(result); // "zzzDOGzzzDOGzzz"
String replaceFirst (String replacement)
final var pattern = Pattern.compile("dog");
final var matcher = pattern.matcher("zzzdogzzzdogzzz");
final var result = matcher.replaceFirst("cat");
System.out.println(result); // "zzzcatzzzdogzzz"
String replaceFirst (Function<MatchResult,String> replacer)
final var pattern = Pattern.compile("dog");
final var matcher = pattern.matcher("zzzdogzzzdogzzz");
final var result = matcher.replaceFirst(mr -> mr.group().toUpperCase());
System.out.println(result); // "zzzDOGzzzdogzzz"
boolean requireEnd ()
final var pattern = Pattern.compile("abc$");
final var matcher = pattern.matcher("abc");
System.out.println(matcher.find()); // true
System.out.println(matcher.group()); // "abc"
System.out.println(matcher.requireEnd()); // true
final var pattern = Pattern.compile("abc");
final var matcher = pattern.matcher("abcd");
System.out.println(matcher.find()); // true
System.out.println(matcher.group()); // "abc"
System.out.println(matcher.requireEnd()); // false
Matcher reset ()
final var pattern = Pattern.compile("a+bc");
final var matcher = pattern.matcher("abc aabc");
System.out.println(matcher.find()); // true
System.out.println(matcher.group()); // "abc"
System.out.println(matcher.find()); // true
System.out.println(matcher.group()); // "aabc"
System.out.println(matcher.find()); // false
matcher.reset();
System.out.println(matcher.find()); // true
System.out.println(matcher.group()); // "abc"
System.out.println(matcher.find()); // true
System.out.println(matcher.group()); // "aabc"
System.out.println(matcher.find()); // false
Matcher reset (CharSequence input)
final var pattern = Pattern.compile("a+bc");
final var matcher = pattern.matcher("abc aabc");
System.out.println(matcher.find()); // true
System.out.println(matcher.group()); // "abc"
System.out.println(matcher.find()); // true
System.out.println(matcher.group()); // "aabc"
System.out.println(matcher.find()); // false
matcher.reset("aaaabc");
System.out.println(matcher.find()); // true
System.out.println(matcher.group()); // "aaaabc"
System.out.println(matcher.find()); // false
Stream<MatchResult> results ()
final var pattern = Pattern.compile("a+bc");
final var matcher = pattern.matcher("abc 012 aabc");
final var stream = matcher.results();
stream.forEach(matchResult -> {
System.out.println(matchResult.group());
});
// Result
// ↓
// "abc"
// "aabc"
int start ()
final var pattern = Pattern.compile("a+bc");
final var input = "aaaaabc";
final var matcher = pattern.matcher(input);
System.out.println(matcher.matches()); // true
final var start = matcher.start();
System.out.println(start); // 0
final var end = matcher.end();
System.out.println(end); // 7
final var group = input.substring(start, end);
System.out.println(group); // "aaaaabc"
final var pattern = Pattern.compile("a+bc");
final var input = "012abcXYZ";
final var matcher = pattern.matcher(input);
System.out.println(matcher.find()); // true
final var start = matcher.start();
System.out.println(start); // 3
final var end = matcher.end();
System.out.println(end); // 6
final var group = input.substring(start, end);
System.out.println(group); // "abc"
int start (int group)
final var pattern = Pattern.compile("(abc|efg)_012_(x..)");
final var matcher = pattern.matcher("abc_012_xyz");
System.out.println(matcher.matches()); // true
System.out.println(matcher.start()); // 0
System.out.println(matcher.end()); // 11
System.out.println(matcher.group()); // "abc_012_xyz"
final var groupCount = matcher.groupCount();
System.out.println(groupCount); // 2
for (int i = 1; i <= groupCount; i++) {
System.out.println("------");
System.out.println("i : " + i);
System.out.println("start : " + matcher.start(i));
System.out.println("end : " + matcher.end(i));
System.out.println("group : " + matcher.group(i));
}
// Result
// ↓
//------
//i : 1
//start : 0
//end : 3
//group : abc
//------
//i : 2
//start : 8
//end : 11
//group : xyz
int start (String name)
final var pattern = Pattern.compile("(?<A>abc|efg)_012_(?<B>x..)");
final var matcher = pattern.matcher("abc_012_xyz");
System.out.println(matcher.matches()); // true
final var result = matcher.toMatchResult();
System.out.println(result.start()); // 0
System.out.println(result.end()); // 11
System.out.println(result.group()); // "abc_012_xyz"
{
final var name = "A";
System.out.println(matcher.start(name)); // 0
System.out.println(matcher.end(name)); // 3
System.out.println(matcher.group(name)); // "abc"
}
{
final var name = "B";
System.out.println(matcher.start(name)); // 8
System.out.println(matcher.end(name)); // 11
System.out.println(matcher.group(name)); // "xyz"
}
MatchResult toMatchResult ()
final var pattern = Pattern.compile("a+bc");
final var matcher = pattern.matcher("abc aabc");
{
System.out.println(matcher.find()); // true
final var result = matcher.toMatchResult();
System.out.println(result.start()); // 0
System.out.println(result.end()); // 3
System.out.println(result.group()); // "abc"
}
{
System.out.println(matcher.find()); // true
final var result = matcher.toMatchResult();
System.out.println(result.start()); // 4
System.out.println(result.end()); // 8
System.out.println(result.group()); // "aabc"
}
String toString ()
final var pattern = Pattern.compile("a+bc");
final var matcher = pattern.matcher("abc aabc");
System.out.println(matcher.find()); // true
final var str = matcher.toString();
// java.util.regex.Matcher[pattern=a+bc region=0,8 lastmatch=abc]
System.out.println(str);
Matcher useAnchoringBounds (boolean b)
final var pattern = Pattern.compile("^abc xyz$");
final var input = "012 abc xyz";
{
final var matcher = pattern.matcher(input);
System.out.println(matcher.hasAnchoringBounds()); // true
// Sets the limits of this matcher's region.
System.out.println(input.substring(4, 11)); // "abc xyz"
matcher.region(4, 11);
System.out.println(matcher.find()); // true
final var result = matcher.toMatchResult();
System.out.println(result.start()); // 4
System.out.println(result.end()); // 11
System.out.println(result.group()); // "abc xyz"
}
{
final var matcher = pattern.matcher(input);
matcher.useAnchoringBounds(false);
System.out.println(matcher.hasAnchoringBounds()); // false
matcher.region(4, 11);
System.out.println(matcher.find()); // false
}
Matcher usePattern (Pattern newPattern)
final var pattern = Pattern.compile("a+bc");
final var matcher = pattern.matcher("aabc xyz");
System.out.println(matcher.find()); // true
System.out.println(matcher.group()); // "aabc"
System.out.println(matcher.find()); // false
matcher.usePattern(Pattern.compile("x.."));
System.out.println(matcher.find()); // true
System.out.println(matcher.group()); // "xyz"
Matcher useTransparentBounds (boolean b)
final var pattern = Pattern.compile("\\by...");
final var input = "xyz12 yz34";
{
final var matcher = pattern.matcher(input);
System.out.println(matcher.hasTransparentBounds()); // false
// Sets the limits of this matcher's region.
System.out.println(input.substring(1, 10)); // "yz12 yz34"
matcher.region(1, 10);
System.out.println(matcher.find()); // true
final var result = matcher.toMatchResult();
System.out.println(result.group()); // "yz12"
}
{
final var matcher = pattern.matcher(input);
matcher.useTransparentBounds(true);
System.out.println(matcher.hasTransparentBounds()); // true
matcher.region(1, 10);
// This matcher to use transparent bounds.
System.out.println(matcher.find()); // true
final var result = matcher.toMatchResult();
System.out.println(result.group()); // "yz34"
}
Related posts
- Ejemplos de API