java 正则表达式 括号嵌套匹配

请问如何通过正则表达式验证括号是否正确匹配?
比如:
正确的:werwer(sdfsdf)sdf,eew(sdf(sdfs))ssdfsf,werwe(sdf{sdfs}sdf(sdfsdf))sdfsf,sdf({sdfdsf(sdfsf)sdf})sd
错误的:werew(sfsf{sfsf)}sdfsdf 此时括号并未正确配对,出现了嵌套。

请各位大师帮忙

{ }转义下就能匹配括号了。

java的正则表达式做不到你的需求

目前正则表达式能支持到这种嵌套结构的程序语言只有 Perl 和 .NET

最终,选择不用正则表达式,通过栈了。
public class BracketMatch {
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void main(String[] args) {
List strList = Arrays.asList("(232){}", "werwer(sdfsdf)sdf,eew(sdf(sdfs))ssdfsf", "werwe(sdf{sdfs}sdf(sdfsdf))sdfsf", "sdf({sdfdsf(sdfsf)sdf})sd", "werew(sfsf{sfsf)}sdfsdf");
for (String str : strList) {
Stack stack = new Stack();
for (int i = 0; i < str.length(); i++) {
// 配对
if (!stack.isEmpty() && (((char) stack.peek() == '(' && str.charAt(i) == ')') || ((char) stack.peek() == '{' && str.charAt(i) == '}'))) {
stack.pop();
} else if (str.charAt(i) == '(' || str.charAt(i) == ')' || str.charAt(i) == '{' || str.charAt(i) == '}') {
stack.push(str.charAt(i));
}
}

        if (stack.isEmpty()) {
            System.out.println("Right:" + str);
        } else {
            System.out.println("Wrong:" + str);
        }
    }
}

}