是否可以使用 contains() 测试以下字符串中的多个子字符串?
"details.php?news=13&action=main&menu_type=&option=single&news_id=4792&pub_no=50"
例如,我可以检查 strcase="details.php"
, "news_id"
同时使用str.contains(strcase)
进行检查?
我不想这样检查:str.contains("details.php")&&str.contains("news_id")
。因为我想同时检查两者:strcase="details.php ** news_id"
喜欢这个声明:
str.replaceAll("\\<[^>]*>","");
可以去掉标签"<?>"
.
最佳答案
string.contains()
与正则表达式不匹配,因此不能像 str.replace()
那样使用它。
您可以使用string.matches()
不过,因为它确实接受正则表达式。
str.matches(".*details\\.php.*news_id.*");
*免责声明*我不擅长正则表达式,但这应该接近你想要的。
关于Java字符串包含函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1155375/