Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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?
s.split("\\((.*?)\\)")
split
(?<=\()[^)]*(?=\))
while
matcher.find()
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)); }
Add a comment
split. Use(?<=\()[^)]*(?=\))regex and awhileloop usingmatcher.find()