Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.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 input = "((1,2,3),(3,4,5),(2,3,4),...)" 目的是得到一个字符串数组,其中每个元素都是一组内部整数,即 array[0] = (1,2,3) array[1] = (3,4,5) 等等 为此,我首先使用这个正则表达式获取内部序列: String inner = input.replaceAll("\\((.*)\\)","$1"); 它是有效的。现在我想买电视机,我正在尝试这个 String sets = i

我正在尝试解析这样的输入字符串

String input = "((1,2,3),(3,4,5),(2,3,4),...)"
目的是得到一个字符串数组,其中每个元素都是一组内部整数,即

array[0] = (1,2,3)
array[1] = (3,4,5)
等等

为此,我首先使用这个正则表达式获取内部序列:

String inner = input.replaceAll("\\((.*)\\)","$1");
它是有效的。现在我想买电视机,我正在尝试这个

String sets = inner.replaceAll("((\\((.*)\\),?)+","$1")

但是我不能得到我期望的结果。我做错了什么?

不要使用
replaceAll
删除末尾的括号。而是使用
String#substring()
。然后,为了获得单个元素,您应该使用
String#split()
,而不是使用
replaceAll

String input=“((1,2,3)、(3,4,5)、(2,3,4))”;
input=input.substring(1,input.length()-1);
//以逗号分隔,后跟“(”和“)”

String[]array=input.split((?@low),它们分别是向后看和向前看。
String input = "((1,2,3),(3,4,5),(2,3,4))";
input = input.substring(1, input.length() - 1);

// split on commas followed by "(" and preceded by ")"
String[] array = input.split("(?<=\\)),(?=\\()");

System.out.println(Arrays.toString(array));