文章标题
2016-04-21 09:11
197 查看
①字符匹配
Pattern p = Pattern.compile(expression); // 正则表达式
Matcher m = p.matcher(str); // 操作的字符串
boolean b = m.matches(); //返回是否匹配的结果
System.out.println(b);
Pattern p = Pattern.compile(expression); // 正则表达式
Matcher m = p.matcher(str); // 操作的字符串
boolean b = m. lookingAt (); //返回是否匹配的结果
System.out.println(b);
Pattern p = Pattern.compile(expression); // 正则表达式
Matcher m = p.matcher(str); // 操作的字符串
boolean b = m..find (); //返回是否匹配的结果
System.out.println(b);
②分割字符串
Pattern pattern = Pattern.compile(expression); //正则表达式
String[] strs = pattern.split(str); //操作字符串 得到返回的字符串数组
③替换字符串
Pattern p = Pattern.compile(expression); // 正则表达式
Matcher m = p.matcher(text); // 操作的字符串
String s = m.replaceAll(str); //替换后的字符串
④查找替换指定字符串
Pattern p = Pattern.compile(expression); // 正则表达式
Matcher m = p.matcher(text); // 操作的字符串
StringBuffer sb = new StringBuffer();
int i = 0;
while (m.find()) {
m.appendReplacement(sb, str);
i++; //字符串出现次数
}
m.appendTail(sb);//从截取点将后面的字符串接上
String s = sb.toString();
⑤查找输出字符串
Pattern p = Pattern.compile(expression); // 正则表达式
Matcher m = p.matcher(text); // 操作的字符串while (m.find()) {
matcher.start() ;
matcher.end();
matcher.group(1);
}
Pattern p = Pattern.compile(expression); // 正则表达式
Matcher m = p.matcher(str); // 操作的字符串
boolean b = m.matches(); //返回是否匹配的结果
System.out.println(b);
Pattern p = Pattern.compile(expression); // 正则表达式
Matcher m = p.matcher(str); // 操作的字符串
boolean b = m. lookingAt (); //返回是否匹配的结果
System.out.println(b);
Pattern p = Pattern.compile(expression); // 正则表达式
Matcher m = p.matcher(str); // 操作的字符串
boolean b = m..find (); //返回是否匹配的结果
System.out.println(b);
②分割字符串
Pattern pattern = Pattern.compile(expression); //正则表达式
String[] strs = pattern.split(str); //操作字符串 得到返回的字符串数组
③替换字符串
Pattern p = Pattern.compile(expression); // 正则表达式
Matcher m = p.matcher(text); // 操作的字符串
String s = m.replaceAll(str); //替换后的字符串
④查找替换指定字符串
Pattern p = Pattern.compile(expression); // 正则表达式
Matcher m = p.matcher(text); // 操作的字符串
StringBuffer sb = new StringBuffer();
int i = 0;
while (m.find()) {
m.appendReplacement(sb, str);
i++; //字符串出现次数
}
m.appendTail(sb);//从截取点将后面的字符串接上
String s = sb.toString();
⑤查找输出字符串
Pattern p = Pattern.compile(expression); // 正则表达式
Matcher m = p.matcher(text); // 操作的字符串while (m.find()) {
matcher.start() ;
matcher.end();
matcher.group(1);
}
相关文章推荐
- C++实验4-项目7穷举
- Oracle-常用语句
- 字体图标
- 北京Uber优步司机奖励政策(4月21日)
- 内存共享和过量使用区别在哪里
- How to save a gecko from gluing disaster
- Struts2框架学习(三) 数据处理
- js 数组
- Effective STL条款17-条款18
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- C++实验4——项目3:乘法口诀表
- 彻底删除项目的VSS源代码管理信息
- Struts2框架学习(二) Action
- matlab中当前文件目录和搜索路径的区别
- Android日期时间选择对话框
- HTTPS的误解(二)
- 【bzoj2666】【cqoi2012】【组装】【贪心】
- Struts2框架学习(一)
- POJ1064 Cable master(二分)
- 搭建hadoop的高可用性(HA)集群