@[toc]

Capture group

The () in the re is simply a capture group

String text = "<textarea rows=\"20\" cols=\"70\">nexus maven repository index properties updating index central</textarea>";
String reg = "
      
       . *? "
      *?>;
Pattern p = Pattern.compile(reg);
Matcher m = p.matcher(text);

while (m.find()) {
  // Matches the entire line
  System.out.println(m.group);
  // Matches the entire line
  System.out.println(m.group(0));
  
      
       )
      *?>
  System.out.println(m.group(1));
  // Match to (.*?)
  System.out.println(m.group(2));
  // Match to (
  System.out.println(m.group(3));
}
Copy the code

In the above code (), there are three capture groups

Non capturing group

Simple understanding of re (? : is a non-capture group and will not be captured

String text = "<textarea rows=\"20\" cols=\"70\">nexus maven repository index properties updating index central</textarea>";
String reg = "(? :
      
        (. *?) (? :)"
      *?>;
Pattern p = Pattern.compile(reg);
Matcher m = p.matcher(text);

While (m.find()) {
  // Matches the entire line
  System.out.println(m.group(0));
  // Match to (.*?)
  System.out.println(m.group(1));
}
Copy the code

In the code above (? : is not recognized as a capture group, so there is a total capture group above