How to parse / split and print the URL?

102 Views Asked by At

Can someone help with url parsing splitting?

I have urls like below -

Actual - https://www.facebook.com/group.php/gid=12345
Expecting - facebook /group.php/gid=12345

Actual - https://www.Test.this.domain/testPath/
Expecting - https wwwtestthisdomain testpath

1

There are 1 best solutions below

0
On

You can use java.net.URI like following:

    URI uri = URI.create("https://www.facebook.com/group.php/gid=12345");
    System.out.println(
        uri.getPath() // prints: /group.php/gid=12345
    );
    System.out.println(
        uri.getHost() // www.facebook.com
    );