java正则使用
2018-03-02 本文已影响4人
Vijay_
- 正则切割
String regex = "正则";
Pattern pattern = Pattern.complie(regex);
String[] strArr = pattern.split("需要正则切割的字符串");
- 正则捕获
String regex = "正则";
Pattern pattern = Pattern.complie(regex);
Matcher matcher = pattern.matcher("需要处理的字符串");
matcher.find();//返回布尔值 表示是否能捕获到
log(matcher.group(0));
log(matcher.group(1));
...
- 正则完全匹配
Pattern pattern = Pattern.compile(".{3}abc.{3}");
Matcher matcher = pattern.matcher("asdabcasd");
boolean b = matcher.matches();
System.out.println(b);//true