Java SE API
Matcher.group()
Return the named capture, or null if it did not participate; requires successful match. Java SE API; example uses Java 21-compatible syntax.
Formal Syntax & Structure
java syntaxjava
String group(String name)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| name | String | Named capture |
Return Value
String
Return the named capture, or null if it did not participate; requires successful match.
Working Example
Example Snippetjava
import java.util.*;import java.util.regex.*;import java.nio.*;import java.nio.charset.*;import java.io.*;import javax.xml.XMLConstants;import javax.xml.parsers.*;import org.xml.sax.*;import org.xml.sax.helpers.DefaultHandler;import org.w3c.dom.*;public class Main { public static void main(String[] args) throws Exception { var m = Pattern.compile("(?<code>[A-Z]{2})-(?<qty>[0-9]{1,3})").matcher("AB-12 CD-3"); while (m.find()) { System.out.println(m.group("code") + ":" + m.group("qty") + " @" + m.start() + ".." + m.end()); } }}