String Functions
Note
These functions can be used when working with and manipulating text and string values.
| Function | Description |
|---|---|
string::capitalize() | Capitalizes each word of a string |
string::concat() | Concatenates strings together |
string::contains() | Checks whether a string contains another string |
string::ends_with() | Checks whether a string ends with another string |
string::join() | Joins strings together with a delimiter |
string::len() | Returns the length of a string |
string::lowercase() | Converts a string to lowercase |
string::matches() | Performs a regex match on a string |
string::repeat() | Repeats a string a number of times |
string::replace() | Replaces an occurrence of a string with another string |
string::reverse() | Reverses a string |
string::slice() | Extracts and returns a section of a string |
string::slug() | Converts a string into human and URL-friendly string |
string::split() | Divides a string into an ordered list of substrings |
string::starts_with() | Checks whether a string starts with another string |
string::trim() | Removes whitespace from the start and end of a string |
string::uppercase() | Converts a string to uppercase |
string::words() | Splits a string into an array of separate words |
string::distance::damerau_levenshtein() | Returns the Damerau–Levenshtein distance between two strings |
string::distance::normalized_damerau_levenshtein() | Returns the normalized Damerau–Levenshtein distance between two strings |
string::distance::hamming() | Returns the Hamming distance between two strings |
string::distance::levenshtein() | Returns the Levenshtein distance between two strings |
string::distance::normalized_levenshtein() | Returns the normalized Levenshtein distance between two strings |
string::distance::osa() | Returns the OSA (Optimal String Alignment) distance between two strings |
string::html::encode() | Encodes special characters into HTML entities to prevent HTML injection |
string::html::sanitize() | Sanitizes HTML code to prevent the most dangerous subset of HTML injection |
string::is_alphanum() | Checks whether a value has only alphanumeric characters |
string::is_alpha() | Checks whether a value has only alpha characters |
string::is_ascii() | Checks whether a value has only ascii characters |
string::is_datetime() | Checks whether a string representation of a date and time matches a specified format |
string::is_domain() | Checks whether a value is a domain |
string::is_email() | Checks whether a value is an email |
string::is_hexadecimal() | Checks whether a value is hexadecimal |
string::is_ip() | Checks whether a value is an IP address |
string::is_ipv4() | Checks whether a value is an IP v4 address |
string::is_ipv6() | Checks whether a value is an IP v6 address |
string::is_latitude() | Checks whether a value is a latitude value |
string::is_longitude() | Checks whether a value is a longitude value |
string::is_numeric() | Checks whether a value has only numeric characters |
string::is_record() | Checks whether a string is a Record ID, optionally of a certain table |
string::is_semver() | Checks whether a value matches a semver version |
string::is_ulid() | Checks whether a string is a ULID |
string::is_url() | Checks whether a value is a valid URL |
string::is_uuid() | Checks whether a string is a UUID |
string::semver::compare() | Performs a comparison between two semver strings |
string::semver::major() | Extract the major version from a semver string |
string::semver::minor() | Extract the minor version from a semver string |
string::semver::patch() | Extract the patch version from a semver string |
string::semver::inc::major() | Increment the major version of a semver string |
string::semver::inc::minor() | Increment the minor version of a semver string |
string::semver::inc::patch() | Increment the patch version of a semver string |
string::semver::set::major() | Set the major version of a semver string |
string::semver::set::minor() | Set the minor version of a semver string |
string::semver::set::patch() | Set the patch version of a semver string |
string::similarity::fuzzy() | Return the similarity score of fuzzy matching strings |
string::similarity::jaro() | Returns the Jaro similarity between two strings |
string::similarity::jaro_winkler() | Return the Jaro-Winkler similarity between two strings |
string::capitalize
The string::capitalize function capitalizes the first letter of each word in a string.
The following example shows this function, and its output, when used in a RETURN statement:
string::concat
The string::concat function concatenates values together into a single string.
The following example shows this function, and its output, when used in a RETURN statement:
Any values received that are not a string will be stringified before concatenation.
Note that the stringified inputs are based on their actual computed values, and not the input tokens themselves. Even an expression can be
string::contains
The string::contains function checks whether a string contains another string.
The following example shows this function, and its output, when used in a RETURN statement:
string::ends_with
Note
The string::ends_with function checks whether a string ends with another string.
The following example shows this function, and its output, when used in a RETURN statement:
string::join
The string::join function joins strings or stringified values together with a delimiter.
If you want to join an array of strings use array::join.
The following example shows this function, and its output, when used in a RETURN statement:
string::len
The string::len function returns the length of a given string in characters.
The following example shows this function, and its output, when used in a RETURN statement:
string::lowercase
The string::lowercase function converts a string to lowercase.
The following example shows this function, and its output, when used in a RETURN statement:
string::matches
The string::matches function performs a regex match on a string.
The following example shows this function, and its output, when used in a RETURN statement:
The second argument can be either a string or a regex.
string::repeat
The string::repeat function repeats a string a number of times.
The following example shows this function, and its output, when used in a RETURN statement:
string::replace
The string::replace function replaces an occurrence of a string with another string.
The following example shows this function, and its output, when used in a RETURN statement:
With regexes added as a data type in version 2.3, the second argument can also be a regex instead of a string.
string::reverse
The string::reverse function reverses a string.
The following example shows this function, and its output, when used in a RETURN statement:
string::slice
The string::slice function extracts and returns a section of a string.
The following example shows this function, and its output, when used in a RETURN statement:
string::slug
The string::slug function converts a string into a human and URL-friendly string.
The following example shows this function, and its output, when used in a RETURN statement:
string::split
The string::split function splits a string by a given delimiter.
The following example shows this function, and its output, when used in a RETURN statement:
string::starts_with
Note
The string::starts_with function checks whether a string starts with another string.
The following example shows this function, and its output, when used in a RETURN statement:
string::trim
The string::trim function removes whitespace from the start and end of a string.
The following example shows this function, and its output, when used in a RETURN statement:
string::uppercase
The string::uppercase function converts a string to uppercase.
The following example shows this function, and its output, when used in a RETURN statement:
string::words
The string::words function splits a string into an array of separate words.
The following example shows this function, and its output, when used in a RETURN statement:
string::distance::damerau_levenshtein
The string::distance::damerau_levenshtein function returns the Damerau-Levenshtein distance between two strings.
The following examples shows this function, and its output in comparison with a number of strings.
string::distance::normalized_damerau_levenshtein
The string::distance::normalized_damerau_levenshtein function returns the normalized Damerau-Levenshtein distance between two strings. Normalized means that identical strings will return a score of 1, with less similar strings returning lower numbers as the distance grows.
The following examples shows this function, and its output in comparison with a number of strings.
string::distance::hamming
The string::distance::hamming function returns the Hamming distance between two strings of equal length.
The following examples shows this function, and its output in comparison with a number of strings.
string::distance::levenshtein
The string::distance::levenshtein function returns the Levenshtein distance between two strings.
The following examples shows this function, and its output in comparison with a number of strings.
string::distance::normalized_levenshtein
The string::distance::normalized_levenshtein function returns the normalized Levenshtein distance between two strings. Normalized means that identical strings will return a score of 1, with less similar strings returning lower numbers as the distance grows.
The following examples shows this function, and its output in comparison with a number of strings.
string::distance::osa
Note
The string::distance::osa_distance function returns the OSA (Optimal String Alignment) distance between two strings.
The following examples shows this function, and its output in comparison with a number of strings.
string::html::encode
The string::html::encode function encodes special characters into HTML entities to prevent HTML injection. It is recommended to use this function in most cases when retrieving any untrusted content that may be rendered inside of an HTML document. You can learn more about its behavior from the original implementation.
The following example shows this function, and its output, when used in a RETURN statement:
string::html::sanitize
The string::html::sanitize function sanitizes HTML code to prevent the most dangerous subset of HTML injection that can lead to attacks like cross-site scripting, layout breaking or clickjacking. This function will keep any other HTML syntax intact in order to support user-generated content that needs to contain HTML styling. It is only recommended to rely on this function if you want to allow the creators of the content to have some control over its HTML styling. You can learn more about its behavior from the original implementation.
The following example shows this function, and its output, when used in a RETURN statement:
string::is_alphanum
Note
The string::is_alphanum function checks whether a value has only alphanumeric characters.
The following example shows this function, and its output, when used in a RETURN statement:
string::is_alpha
Note
The string::is_alpha function checks whether a value has only alpha characters.
The following example shows this function, and its output, when used in a RETURN statement:
string::is_ascii
Note
The string::is_ascii function checks whether a value has only ascii characters.
The following example shows this function, and its output, when used in a RETURN statement:
string::is_datetime
Note
The string::is_datetime function checks whether a string representation of a date and time matches either the datetime format or a user-specified format.
If no second argument is specified, this function will check if a string is a datetime or a format that can be cast into a datetime.
With a second argument, this function will check if a string matches the user-specified format. The output false may be returned in this case even if the input string is a valid datetime.
This can be useful when validating datetimes obtained from other sources that do not use the RFC 3339 format.
string::is_domain
Note
The string::is_domain function checks whether a value is a domain.
The following example shows this function, and its output, when used in a RETURN statement:
string::is_email
Note
The string::is_email function checks whether a value is an email.
The following example shows this function, and its output, when used in a RETURN statement:
string::is_hexadecimal
Note
The string::is_hexadecimal function checks whether a value is hexadecimal.
The following example shows this function, and its output, when used in a RETURN statement:
string::is_ip
Note
The string::is_ip function checks whether a value is an IP address.
The following example shows this function, and its output, when used in a RETURN statement:
string::is_ipv4
Note
The string::is_ipv4 function checks whether a value is an IP v4 address.
The following example shows this function, and its output, when used in a RETURN statement:
string::is_ipv6
Note
The string::is_ipv6 function checks whether a value is an IP v6 address.
The following example shows this function, and its output, when used in a RETURN statement:
string::is_latitude
Note
The string::is_latitude function checks whether a value is a latitude value.
The following example shows this function, and its output, when used in a RETURN statement:
string::is_longitude
Note
The string::is_longitude function checks whether a value is a longitude value.
The following example shows this function, and its output, when used in a RETURN statement:
string::is_numeric
Note
The string::is_numericfunction checks whether a value has only numeric characters.
The following example shows this function, and its output, when used in a RETURN statement:
string::is_semver
Note
The string::is_semver function checks whether a value matches a semver version.
The following example shows this function, and its output, when used in a RETURN statement:
string::is_ulid
Note
The string::is_ulid function checks whether a string is a ULID.
The following example shows this function, and its output, when used in a RETURN statement:
string::is_url
Note
The string::is_url function checks whether a value is a valid URL.
The following example shows this function, and its output, when used in a RETURN statement:
string::is_record
Note
The string::is_record function checks whether a string is a Record ID.
The second argument is optional and can be used to specify the table name that the record ID should belong to. If the table name is provided, the function will check if the record ID belongs to that table only.
string::is_uuid
Note
The string::is_uuid function checks whether a string is a UUID.
The following example shows this function, and its output, when used in a RETURN statement:
string::semver::compare
The string::semver::compare function performs a comparison on two semver strings and returns a number.
A value of -1 indicates the first version is lower than the second, 0 indicates both versions are equal, and 1 indicates the first version is higher than the second.
The following example shows this function, and its output, when used in a RETURN statement:
string::semver::major
The string::semver::major function extracts the major number out of a semver string.
The following example shows this function, and its output, when used in a RETURN statement:
string::semver::minor
The string::semver::minor function extracts the minor number out of a semver string.
The following example shows this function, and its output, when used in a RETURN statement:
string::semver::patch
The string::semver::patch function extracts the patch number out of a semver string.
The following example shows this function, and its output, when used in a RETURN statement:
string::semver::inc::major
The string::semver::inc::major function increments the major number of a semver string. As a result, the minor and patch numbers are reset to zero.
The following example shows this function, and its output, when used in a RETURN statement:
string::semver::inc::minor
The string::semver::inc::minor function increments the minor number of a semver string. As a result, the patch number is reset to zero.
The following example shows this function, and its output, when used in a RETURN statement:
string::semver::inc::patch
The string::semver::inc::patch function increments the patch number of a semver string.
The following example shows this function, and its output, when used in a RETURN statement:
string::semver::set::major
The string::semver::set::major function sets the major number of a semver string without changing the minor and patch numbers.
The following example shows this function, and its output, when used in a RETURN statement:
string::semver::set::minor
The string::semver::set::minor function sets the minor number of a semver string without changing the major and patch numbers.
The following example shows this function, and its output, when used in a RETURN statement:
string::semver::set::patch
The string::semver::set::patch function sets the patch number of a semver string without changing the major and minor numbers.
The following example shows this function, and its output, when used in a RETURN statement:
string::similarity::fuzzy
The string::similarity::fuzzy function allows a comparison of similarity to be made. Any value that is greater than 0 is considered a fuzzy match.
The similarity score is not based on a single score such as 1 to 100, but is built up over the course of the algorithm used to compare one string to another and will be higher for longer strings. As a result, similarity can only be compared from a single string to a number of possible matches, but not multiple strings to a number of possible matches.
While the first two uses of the function in the following example compare identical strings, the longer string returns a much higher fuzzy score.
A longer example showing a comparison of similarity scores to one another:
string::similarity::jaro
The string::similarity::jaro function returns the Jaro similarity between two strings. Two strings that are identical have a score of 1, while less similar strings will have lower scores as the distance between them increases.
The following examples shows this function, and its output in comparison with a number of strings.
string::similarity::jaro_winkler
The string::similarity::jaro_winkler function returns the Jaro-Winkler similarity between two strings. Two strings that are identical have a score of 1, while less similar strings will have lower scores as the distance between them increases.
The following examples shows this function, and its output in comparison with a number of strings.
Method chaining
Method chaining allows functions to be called using the . dot operator on a value of a certain type instead of the full path of the function followed by the value.
This is particularly useful for readability when a function is called multiple times.