我有一些代码:
String url1 = "http://shop.lenovo.com/SEUILibrary/controller/e/web/LenovoPortal/en_US/cart.workflow:ShowCart?shopping-menu-s...";
String url2 = "shop.lenovo.com/(.*)/en_US/cart";
Pattern p = Pattern.compile(url2);
Matcher m = p.matcher(url1);
但是m.matches()对我来说是假的。为什么呢?
答案 0 :(得分:2)
请尝试使用
代替您的代码 String url1 = "http://shop.lenovo.com/SEUILibrary/controller/e/web/LenovoPortal/en_US/cart.workflow:ShowCart?shopping-menu-s...";
String subS1 = "shop.lenovo.com/";
Pattern p1 = Pattern.compile(subS1);
Matcher match1 = p1.matcher(url1);
String subS2 = "en_US/cart";
Pattern p2 = Pattern.compile(subS2);
Matcher match2 = p2.matcher(url1);
if (match1.find() && match2.find())
{
// Whatever you like
}