Question

i cant figure out how i manage to solve the problem of getting information out of square brackets as well as the normal ones. I want the content of them both. i tried:

Pattern p = Pattern.compile("\\[[^\\]]*\\]"); 
Pattern p1 = Pattern.compile("\\[|\\([^\\)]*|[^\\]]*\\]|\\)"); 
Pattern p2 = Pattern.compile("\\[|\\([^{\\]|\\)}]*\\]|\\)");

p works perfectly for the squared ones only and then i tried to add the normal braces, but no success.
a sample of a string would be

"(info1) something-uninteresting [info2] s.u. [info3] s.u. (info4)"
Was it helpful?

Solution

Try the following:

[\\[(][^\\])]*[\\])]

OTHER TIPS

Try the following:

(\\(.*?\\)|\\[.*?\\])*?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top