extract_url_host
Use the extract_url_host() function to return the host portion of a given URL string.
Syntax
extract_url_host (<url_string>)Parameters
url_string
string
Yes
The input string literal or field containing the URL from which the host needs to be extracted.
Returns
The extract_url_host() function returns a string representing the host of the URL.
Usage notes
The function always returns the host value in lowercase characters, regardless of the input URL's original casing.
This function is typically used within the
alterstage to create new fields or modify existing ones based on extracted URL data, or within thefilterstage for conditional logic.If the input
url_stringis NULL, the function returns NULL.
Examples
Example 1: Basic host extraction from a standard URL
Goal: Extract the host from a common HTTPS URL.
XQL code:
Explanation: The query extracts the host "www.paloaltonetworks.com" from the provided URL string.
Output:
101
www.paloaltonetworks.com
Example 2: Host extraction from a URL with user, password, and port
Goal: Extract the host from a complex URL that includes user credentials and port numbers.
XQL code:
Explanation: extract_url_host() successfully isolates "a.b" as the host, ignoring the user, password, port, path, and query parameters.
Output:
101
a.b
Example 3: Host extraction with mixed-case input
Goal: Extract the host from a URL containing uppercase letters, demonstrating the automatic lowercasing behavior.
XQL code:
Explanation: Despite "www.Example.Co.UK" having mixed casing, the function returns "www.example.co.uk" in all lowercase, demonstrating its built-in lowercasing behavior.
Output:
101
<www.example.co.uk>
Example 4: Host extraction from a URL with multiple suffixes/paths
Goal: Extract the full hostname from a URL that includes subdomains and extended paths.
XQL code:
Explanation: The function correctly identifies the entire host, including subdomains, regardless of the trailing path components.
Output:
101
www.test.paloaltonetworks.com
Example 5: Handling NULL input
Goal: Demonstrate the function's behavior when provided with a NULL input.
XQL code:
Explanation: Consistent with standard XQL function behavior, if the input to extract_url_host() is NULL, the function returns NULL.
Output:
101
NULL
NULL
Example: Host extraction from a URL string
Goal: Return a single record from the sample_xql_raw dataset showing the extracted host name from a specific URL string ("https://www.test.paloaltonetworks.com").
XQL Code:
Explanation:
The query starts by accessing the xdr_data dataset.
The alter stage creates a new field named url_host.
The extract_url_host() function parses the provided URL string and isolates the host component (www.test.paloaltonetworks.com).
The fields stage restricts the final output to only show the newly created url_host column.
The
limit 1stage ensures that only a single result is returned.
Output:
"www.test.paloaltonetworks.com"
Related articles
Functions:
extract_url_pub_suffix,extract_url_registered_domainDatasets:
xdr_data
Last updated
Was this helpful?
