I need to capture strings in brackets within a string. I found a solution that did not solve my problem fully: \[(.*?)\]
Usage like this:
Matcher mat = Pattern.compile("\[(.*?)\]").matcher(stringlToVerify);
if(mat.find()) {
// Faz o que quero
}
So, if I run the regex with: 'ol[a' + 'm]undo'
It will get: [a' + 'm]
But in that case it is not to catch because the two strings are being concatenated, so it does not make sense.
Example of what I need:
Entrada Captura
1 + [aa] [aa]
[bb] + 2 [bb]
'a' + [cc] [cc]
['ola' + 'mundo'] ['ola' + 'mundo']
'[a' + 'b]'
'[' + ']'
[] [] (ou nada, também serve)
'Ola [world] legal'
Oi ['[aa]'] ola '[aa]'
In the latter case, if you can not do it simply, that's fine. I made a method that removes all strings in single quotation marks.