您的位置:首页 > 编程语言

编程小技巧共享

2009-08-05 20:16 183 查看
我在平时积累的一些封装小工具,方便使用的,共享出来
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
* 正则表达式的封装,简化使用,原先使用多个类返回使用多步测试,比较麻烦
*/
package wwwlgy.tools.reg;

import java.util.regex.*;

/**
*
* @author l33187
*/
public class MyRegexp {
Pattern p;
Matcher m;

public MyRegexp (String rxp){
this.p = Pattern.compile(rxp);
}
/**
* 直接测试匹配,不用多步骤,一步到位
* @param str 要测试的字符串
* @return 返回匹配结果
*/
public boolean test(String str){
this.m = this.p.matcher(str);
return this.m.find();
}
////////////////////////////////////
//下面都是对Matcher的原始封装函数,不再说明
//////////////////////////////////////
public boolean matches(){
return this.m.matches();
}

public boolean find(){
return this.m.find();
}

public String group(){
return this.m.group();
}

public String group(int idx){
return this.m.group(idx);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: