Try out regular expressions : Pattern « Development « Java Tutorial






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

public class MainClass {
  public static void main(String[] args) {
    if (args.length < 2) {
      System.out.println("Usage:\n" + "java MainClass " + "characterSequence regularExpression+");
      System.exit(0);
    }
    System.out.println("Input: \"" + args[0] + "\"");
    for (int i = 1; i < args.length; i++) {
      System.out.println("Regular expression: \"" + args[i] + "\"");
      Pattern p = Pattern.compile(args[i]);
      Matcher m = p.matcher(args[0]);
      while (m.find()) {
        System.out.println("Match \"" + m.group() + "\" at positions " + m.start() + "-"
            + (m.end() - 1));
      }
    }
  }
}








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)