RegEx3.java
Select all
/* RegEx3.java David Klick 3/8/06 Demonstrates regular expression use. */ import java.util.regex.*; public class RegEx3 { public static void main(String[] args) { String[] sarr = { "to", "it", "sit", "attack", "bath", "art", "into", "this", "mutt" }; String[] patterns = { ".t", "t.", "...$", "^.t", "t.$", "^..$", ".+t", ".?t", "^[aeiou]", "^[^aeiou]" }; System.out.print("Words: "); for (String s: sarr) System.out.print(s + " "); System.out.print("\n\n"); for (String s : patterns) { Pattern p = Pattern.compile(s); Matcher m; System.out.print(p.pattern() + "\n "); for (int i=0; i