Last active
January 2, 2022 16:07
-
-
Save turboBasic/bf7ae6bf65e02a5f9a4edc6d92e0e6c1 to your computer and use it in GitHub Desktop.
getHostFromUrl() #groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String getHostFromUrl(String url) { | |
url | |
.replaceAll('^[a-z]+://', '') | |
.replaceAll('(/.*)?$', '') | |
.replaceAll('(:[0-9]+)?$', '') | |
} | |
def getHostFromUrlSpec() { | |
expect: | |
getHostFromUrl('https://example.com:9999/path.ext') == 'example.com' | |
getHostFromUrl('https://example.com/path.ext') == 'example.com' | |
getHostFromUrl('https://example.com') == 'example.com' | |
getHostFromUrl('ssh://example.com') == 'example.com' | |
getHostFromUrl('file:///usr/local/bin/sh') == '' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment