0

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

Emma
  • 27,428
  • 11
  • 44
  • 69
  • 1
    Does this answer your question? [How to split a string in Java](https://stackoverflow.com/questions/3481828/how-to-split-a-string-in-java) – Docteur Oct 19 '20 at 05:41
  • How does it work ? second one has https and www in result but first one only has "facebook" – Fabich Oct 19 '20 at 09:55

1 Answers1

0

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
    );
Timur Levadny
  • 510
  • 4
  • 13