Friday, November 25, 2005

Java Regualr Expression for Alphabet only String

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

public class Main {
   public static void main(String[] args) {
      //[a-zA-Z] means from a to z or A to Z, * means many of none of them
      Pattern p = Pattern.compile("[a-zA-Z]*");
      Matcher m = p.matcher("aadddaaiiiii");
      boolean b = m.matches();
      System.out.println(b);
   }
}

No comments: