(JAVA)Regular Expression测试

        前一段做毕业设计期间,由于想把程序做的好一点就学习了一下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。还有毕设答辨时表现不太好,,还要努力啊!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值