Closed. This question is not reproducible or was caused by typos。它当前不接受答案。                                                                                                                                                                                                        想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。                                    4个月前关闭。                        我有一个HTTP请求输入String解码,应该检查它是否包含任何运算符,例如“ [$,=?@#'。()%!] ^”。我用谷歌搜索并找到了一些根据它们的工作代码,我已经将值传递给了运算符,但是它不起作用:String urlParameters = httpRequest.getQueryString();try { String prevURL=""; String decodeURL=urlParameters; while(!prevURL.equals(decodeURL)) { prevURL=decodeURL; decodeURL=URLDecoder.decode( decodeURL, "UTF-8" ); } urlParameters=decodeURL; } catch (Exception e) { System.out.println("Exception on decoding:" + e);}Pattern pp = Pattern.compile("[$,=?@#'<>.()%!]^");Matcher mm = pp.matcher(urlParameters);if (mm.find()) { System.out.println("There is an Operator");}如果urlParameters具有上述任何一个运算符,则应打印“ There is a Operator” (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 模式结尾处有^运算符-"[$,=?@#'<>.()%!]^"。^-用于匹配字符串的第一个字符之前的位置。从您的模式中删除^,您的逻辑应该起作用如果需要^作为特殊字符集的一部分,请将其包含在[]中Pattern pp = Pattern.compile("[$,=?@#'^<>.()%!]"); (adsbygoogle = window.adsbygoogle || []).push({});
10-05 23:27