Pattern.compile('(?m)(\\S+)\\s+((\\S+)\\s+(\\S+))$').matcher : Pattern « Development « Java Tutorial






import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MainClass {

  static public final String poem = "PC Bird Cow Slow Doe Hole Joe\n"
      + "Shy Shift Sleep Do Down Doing.\n" + "Yes No How Whose\n";

  public static void main(String[] args) {
    Matcher m = Pattern.compile("(?m)(\\S+)\\s+((\\S+)\\s+(\\S+))$").matcher(poem);
    while (m.find()) {
      for (int j = 0; j <= m.groupCount(); j++)
        System.out.print("[" + m.group(j) + "]");
      System.out.println();
    }
  }
}
/**/
[Doe Hole Joe][Doe][Hole Joe][Hole][Joe]
[Do Down Doing.][Do][Down Doing.][Down][Doing.]
[No How Whose][No][How Whose][How][Whose]








6.34.Pattern
6.34.1.Try out regular expressions
6.34.2.Pattern.compile('(?m)(\\S+)\\s+((\\S+)\\s+(\\S+))$').matcher
6.34.3.Displays directory listing using regular expressions
6.34.4.Pattern.compile('!!').split
6.34.5.Pattern.compile('[frb][aiu][gx]).matcher('fix the rug with bags')
6.34.6.Pattern.compile(^java, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE)