Answer the question
In order to leave comments, you need to log in
How to get the values of an array with a regular expression?
\\"bla\\":\[(?:\\"(\d+)\\",?)+\]
//\"bla\":[\"1000\",\"1002\",\"1\",\"22222\",\"333\",\"3333\",\"33344\"]
Matcher matcher = pattern.matcher(str);
if (matcher.find()) {
System.out.println(matcher.group(1));
}
Answer the question
In order to leave comments, you need to log in
I don't think it's possible. It is easier and clearer to do it in two steps, first extract the contents of
"bla" from the square brackets:\[([^\]]*)\]
And then from the found contents of the square brackets get all the groups
"([0-9]+)"
String input = "\"bla\":[\"1000\",\"1002\",\"1\",\"22222\",\"333\",\"3333\",\"33344\"]";
Pattern pattern = Pattern.compile("([0-9]){1,}");
Matcher matcher = pattern.matcher(input.replaceAll("\"bla\":\\[([^\\]])\\]", "$1"));
while (matcher.find()) {
System.out.println("g:"+ matcher.start() + " " + matcher.group());
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question