Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java正则表达式查找但不包含在组中_Java_Regex - Fatal编程技术网

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*) 
(.+[^\"])