作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个已解码的 HTTP 请求输入字符串,应检查它是否包含“[$,=?@#'<>.()%!]^”等运算符。
我用谷歌搜索并根据它们找到了一些工作代码,我已经使用运算符传递了值,但它不起作用:
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 an Operator”
最佳答案
您有^
模式末尾的运算符 - "[$,=?@#'<>.()%!]^"
。
^
- 用于匹配字符串第一个字符之前的位置。
删除^
根据你的模式和你的逻辑应该有效
如果^
需要作为特殊字符集的一部分,请将其包含在 []
中
Pattern pp = Pattern.compile("[$,=?@#'^<>.()%!]");
关于java - 模式匹配不适用于 JAVA 中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59561479/
我是一名优秀的程序员,十分优秀!