Reluctant quantifier acting greedy
This question already has an answer here:
 {1} in regex is redundant since any element without specified quantifier needs to be found once.  Also making it reluctant doesn't make sense since it doesn't describe range of possible repetitions (like {min,max} where adding ? would tell regex engine to make number of repetitions in that range as close to min as possible).  Here {n} describes precise number of repetition so min = max = n .  
 Now you should be able to solve your problem by making .+ (content between brackets) reluctant.  To do so use .+?  .  
So try with:
String regex = "(((|[)(.+?)()|]))";
上一篇: 理解量词
下一篇: 不情愿量词贪婪
