Exemple #1
0
 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++) printnb("[" + m.group(j) + "]");
     print();
   }
 }
 public static void main(String[] args) {
   if (args.length < 2) {
     print("Usage:\njava TestRegularExpression " + "characterSequence regularExpression+");
     System.exit(0);
   }
   print("Input: \"" + args[0] + "\"");
   for (String arg : args) {
     print("Regular expression: \"" + arg + "\"");
     Pattern p = Pattern.compile(arg);
     Matcher m = p.matcher(args[0]);
     if (!m.find()) print("No match found for " + "\"" + arg + "\"");
     m.reset();
     while (m.find()) {
       print(
           "Match \""
               + m.group()
               + "\" at position "
               + m.start()
               + ((m.end() - m.start() < 2) ? "" : ("-" + (m.end() - 1))));
     }
   }
 }