strings.extract_hostname

Supported in:
strings.extract_hostname(string)

Description

Extracts the hostname from a string. This function is case sensitive.

Param data types

STRING

Return type

STRING

Code samples

Example 1

This example returns an empty string.

strings.extract_hostname("") = ""
Example 2

random string, not a URL

strings.extract_hostname("1234") = "1234"
Example 3

multiple backslashes

strings.extract_hostname("\\\\") = ""
Example 4

non-English characters handled gracefully

strings.extract_hostname("http://例子.卷筒纸.中国") = "例子.卷筒纸.中国"
Example 5

handling URIs

strings.extract_hostname("mailto:?to=&subject=&body=") = "mailto"
Example 6

multiple characters before actual URL

strings.extract_hostname("     \t   !$5*^)&dahgsdfs;http://www.google.com") = "www.google.com"
Example 7

special characters in URI #

strings.extract_hostname("test#@google.com") = "test"
Example 8

special characters in URL #

strings.extract_hostname("https://test#@google.com") = "test"