- Pattern
如:
Pattern EMPTY_LINE = Pattern.compile("^\\s*(#.*)?$");
^
表示完全匹配前面,就是以什么开头,$
表示完全匹配后面,就是以什么结尾,综合起来就是完全匹配,代表能匹配出来的字符串就一个
.*表示0个或多个任意字符
()
表示匹配的子项
- Matcher
Matcher matcher= EMPTY_LINE.matcher(" #."); while (matcher.find()) { System.out.println(matcher.group(1)); };
matcher.find()
是迭代所有匹配的项
matcher.group()
等效与matcher.group(0)
,就是这个匹配项的字符串
matcher.group(1)
是匹配项的子项,就是()
里面的
网友评论