Java解析正則表達式

package com.yzy;
import java.util.regex.*;
public class Test {

 /**
  * @param args
  */
 public static void main(String[] args) {
  Pattern p=Pattern.compile("^[a-z]+");

  Matcher m=p.matcher("a233"); //true
  //Matcher m=p.matcher("2233"); //false

  //m.find();  //true
  System.out.println(m.find());//true

  /*
  m.groupCount();  //返回2,因爲有2組

  m.start(1);  //返回0 返回第一組匹配到的子字符串在字符串中的索引號

  m.start(2);  //返回3

  m.end(1);  //返回3 返回第一組匹配到的子字符串的最後一個字符在字符串中的索引位置.

  m.end(2);  //返回7

  m.group(1);  //返回aaa,返回第一組匹配到的子字符串

  m.group(2);  //返回2223,返回第二組匹配到的子字符串
*/


 }

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章