đối sánh mẫu cho Chuỗi có “{”

Đầu tiên tôi làm điều này -

String str = "{\"hits\":[{\"links_count\":6,\"forum_count\":11}],\"totalHitCount\":1}";

        Assert.assertTrue(str.matches("{\"hits\":[{\"links_count\":[0-9]{1,},\"forum_count   \":11}],\"totalHitCount\":[0-9]{1,}}"),
            "Partnership message does not appear");

Điều này khiến tôi gặp lỗi sau -

 Exception in thread "main" java.util.regex.PatternSyntaxException: Illegal repetition
{"hits":[\{"links_count":[0-9]{1,},"forum_count":11}],"totalHitCount":[0-9]{1,}}

Sau đó, tôi đã làm (thoát khỏi "{") -

String str = "\\{\"hits\":[\\{\"links_count\":6,\"forum_count\":11\\}],\"totalHitCount\":1\\}";

    Assert.assertTrue(str.matches("\\{\"hits\":[\\{\"links_count\":[0-9]{1,},\"forum_count\":11\\}],\"totalHitCount\":[0-9]{1,}\\}"),
            "Partnership message does not appear");

và gặp lỗi sau -

Exception in thread "main" java.lang.AssertionError: Partnership message does not appear expected:<true> but was:<false>

Tôi còn thiếu gì ở đây?

7
задан Jeff Mercado 9 June 2011 в 04:54
поделиться