Domanda

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)"
È stato utile?

Soluzione

Try the following:

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

Altri suggerimenti

Try the following:

(\\(.*?\\)|\\[.*?\\])*?
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top