java正则表达式查找但不包含在组中
考虑这个简单的例子:java正则表达式查找但不包含在组中,java,regex,Java,Regex,考虑这个简单的例子: String myPattern= "\\[(\"(.+[^\"])\",\\s*){1,3}(\"(.+[^\"])\")\\]"; final Pattern compile1 = Pattern.compile(myPattern); final Matcher matcher = compile1.matcher(myString); 我在matcher中有两个组用于此“((.+[^\“])\”,\s*){1,3}”: 及 但是我只想要一个组-(.+[^\“])。
String myPattern= "\\[(\"(.+[^\"])\",\\s*){1,3}(\"(.+[^\"])\")\\]";
final Pattern compile1 = Pattern.compile(myPattern);
final Matcher matcher = compile1.matcher(myString);
我在matcher中有两个组用于此“((.+[^\“])\”,\s*){1,3}
”:
及
但是我只想要一个组-(.+[^\“])
。如何将要求值的{1,3}表达式括在括号中,使其不包含在组中?
我试着用方括号,但没有用。我真的受够了这个问题,最后决定问,因为我经常不得不这样做
matcher.getGroup(1);
matcher.getGroup(3);
使用非捕获组(?:)
即(?:yourregex)
它的意思是匹配,但不包括在捕获组中。其名称为“非捕获组”;)
((.+[^\"])\",\s*)
(.+[^\"])