JAVA正则表达式4种常用功能
作者: 佚名, 出处:IT专家网论坛, 责任编辑: 包春林,
2008-05-09 04:00
正则表达式在字符串处理上有着强大的功能,sun在jdk1.4加入了对它的支持
下面简单的说下它的4种常用功能:
查询:
| String str="abc efg ABC";
String regEx="a|f"; //表示a或f Pattern p=Pattern.compile(regEx); Matcher m=p.matcher(str); boolean rs=m.find(); |
提取:
| String regEx=".+\\\\(.+)$";
String str="c:\\dir1\\dir2\\name.txt"; Pattern p=Pattern.compile(regEx); Matcher m=p.matcher(str); boolean rs=m.find(); for(int i=1;i<=m.groupCount();i++){ System.out.println(m.group(i)); } |
分割:
| String regEx="::";
Pattern p=Pattern.compile(regEx); String[] r=p.split("xd::abc::cde"); |
- 本文关键词:

