0

String s = "Length(1-2), Width(3-4), Height(5-6)"

I need to get values only inside brackets i.e -

[1-2, 3-4, 5-6]

When I use s.split("\\((.*?)\\)"), I get values ​​outside my parentheses, but I need inside. How can I do this?

2
  • Don't use split. Use (?<=\()[^)]*(?=\)) regex and a while loop using matcher.find() Commented Dec 6, 2018 at 10:03
  • You can match them with your regex. Commented Dec 6, 2018 at 10:03

1 Answer 1

0
String s = "Length(1-2), Width(3-4), Height(5-6)";

Pattern p = Pattern.compile("\\((.*?)\\)");
Matcher m = p.matcher(s);

while(m.find()) {
  System.out.println(m.group(1));
}
Sign up to request clarification or add additional context in comments.

Comments