CSDN博客

img rebollee

(JAVA)Regular Expression测试

发表于2004/10/28 15:02:00  280人阅读

分类: JAVA

        前一段做毕业设计期间,由于想把程序做的好一点就学习了一下Regular Expression,然后就有了以下代码,做测试。

/** RETry.class
  * Author: Jack
  * Date: 2004-10
   */
import java.util.regex.*;
import java.io.*;

public class RETry {
    public static void main(String[] args) {
             Pattern p;
             Matcher m;
             BufferedReader in =
                     new BufferedReader(new InputStreamReader(System.in));
             boolean done = false;
             String line = new String();

             System.out.println("Copyright @ 2004,Author Jack Lee,Version 1.0");
             System.out.println("Welcom to use!");

             System.out.print("Now Give me a Pattern:");
             try {
                 line = in.readLine();
             }
             catch (IOException e){}
 
             if (line.equals("quit")){
                 System.out.println("Bye!");
                 System.exit(0);
             }

             p = Pattern.compile(line);

             while (!done) {
                 System.out.print("command>>");

             try {
                  line = in.readLine();
             }
             catch(IOException e){
             }
    
             if (line.equals("quit")) {
                  done = true;
                  System.out.println("Bye!");
                  continue;
             } // end of if ()
            else if (line.equals("change")) {
                  System.out.print("Now change the Pattern:");
                  try {
                      line = in.readLine();
                  }
                  catch (IOException e){
                  }
                  if (line.equals("quit")) {
                      System.out.println("Bye!");
                      System.exit(0);
                  }
                  p = Pattern.compile(line);
                  continue;
             } // end of else if ()
    
             m = p.matcher(line);
    
             if (m.matches()) {
                  System.out.println("Match!");
             } // end of if ()
             else {
                  System.out.println("Don't Match!");
             } // end of else
          
         } // end of while ()
 
    } // end of main()
}///:~

附: j2sdk1.4.2,平台WinXP。还有毕设答辨时表现不太好,,还要努力啊!!!

阅读全文
0 0

相关文章推荐

img
取 消
img