0

I have some code:

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);

But m.matches() return for me false. Why?

Tipok
  • 675
  • 8
  • 26

1 Answers1

2

Instead of your code please try this

    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
    }
Anurag Dadheech
  • 629
  • 1
  • 5
  • 14
  • 1
    I get regex and url in json, and regex each time different. You described a particular solution. I just started using the function find(). Thanks! – Tipok Mar 30 '17 at 02:44