我正在尝试编写一个正则表达式来检查 URL 是否包含 ci
、ci1
、ci2
或 stag
或
如果url包含/preview
https://regex101.com/r/aKHx9g/2/tests
例如,正则表达式应该匹配
http://ci.company.com
http://stag.company.com
http://www.company.com/preview
https://www.company.com/preview
这个不应该匹配
http://www.company.com/article
http://company.com/article
https://company.com/article
不确定正则表达式是否能够捕获它?
我似乎无法弄清楚如何在正则表达式中执行 OR
条件。这是我到目前为止所得到的。
https?:\/\/(ci|stag|ci2|ci3)\..*
最佳答案
您可以简单地使用String.contains(/*something*/)
:
if(url.contains("/preview") || url.contains("ci") /*and the other
things that you want to check*/){
//do things accordingly
}
关于java - 如何检查 URL 是否包含/预览或子域是 CI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41172043/