编程小技巧共享
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);
}
}
/*
* 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);
}
}
相关文章推荐
- Java编程小技巧
- 木马编程小技巧
- C#-- 几个C#编程的小技巧[转]
- (进程编程)共享内存总结(笔记整理)
- .NET 下的 POP3 编程代码共享
- matlab 编程小技巧积累
- hadoop编程小技巧(1)---map端聚合
- 几个C#编程的小技巧
- 积累的VC编程小技巧之标题栏和菜单
- PHP安全编程:共享主机的源码安全
- 几个C#编程的小技巧
- 小技巧:用C#编程合并多个WORD文档
- java并发编程之:线程共享数据的方式
- 几个C#编程的小技巧
- linux网络编程之共享内存简介和mmap 函数
- 编程小技巧
- 用Pthreads进行共享内存编程----HelloWorld
- 我的并行计算之路(五)Pthreads共享内存编程
- VB编程的8个小技巧