^ 匹配输入字符串的开始位置。如果设置了RegExp对象的Multiline属性,^也匹配“\n”或“\r”之后的位置
[^a] 在此^表示非的意思,匹配非a的字符
\s 匹配任何空白字符,包括空格、制表符、换页符等等。等价于[ \f\n\r\t\v]
\S 匹配任何非空白字符。等价于[^ \f\n\r\t\v]
匹配换行符:
import java.util.regex.Matcher import java.util.regex.Pattern String str = "nihaobuhao<plugin><groupId>aaa</groupId></plugin>\n" + "<plugin><groupId>bbb</groupId></plugin>\n" + "<plugin><groupId>ccc</groupId></plugin>\n" + "wohuihenhao";
//匹配所有<plugin></plugin>的东西 String reg = "(<plugin><groupId>.+</groupId></plugin>\\s)+"; Pattern pattern = Pattern.compile(reg); Matcher matcher = pattern.matcher(str); if(matcher.find()){ println(matcher.group()); }