Chapter Eight: Regular Expression Applications: Formal Language, Chapter 8, Slide 1
Chapter Eight: Regular Expression Applications: Formal Language, Chapter 8, Slide 1
/**
* A Java application to demonstrate the Java package
* java.util.regex. We take one command-line argument,
* which is treated as a regexp and compiled into a
* Pattern. We then use that pattern to filter the
* standard input, echoing to standard output only
* those lines that match the Pattern.
*/
String s = in.readLine();
while (s!=null) {
Matcher m = p.matcher(s);
if (m.matches()) System.out.println(s);
s = in.readLine();
}
}
}