I have been thinking about how to write a regular expression to determine whether a string is a json array. If I want to write a regular expression, I can't figure out a solution first, check whether it is wrapped by {} or []. The test code is as follows:
Pattern pattern = Pattern. compile ("(^ \\[. * \] $ | ^ \\{. * \\}$) {1} "); String s1 =" [aaa] "; // true String s2 =" [aaa "; String s3 =" aaa] "; string s4 = "{aaa}"; // true String s5 = "{aaa"; String s6 = "aaa}"; String s7 = "aaa"; System. out. println (pattern. matcher (s1 ). matches (); System. out. println (pattern. matcher (s2 ). matches (); System. out. println (pattern. matcher (s3 ). matches (); System. out. println (pattern. matcher (s4 ). matches (); System. out. println (pattern. matcher (s5 ). matches (); System. out. println (pattern. matcher (s6 ). matches (); System. out. println (pattern. matcher (s7 ). matches ());
We hope to find a solution as soon as possible.
This article from the "speechless" blog, please be sure to keep this source http://reven.blog.51cto.com/4747346/1286946