NoteSince version 3.0.0-alpha.8, the
::is::functions (e.g.string::is::domain()) now use underscores (e.g.string::is_domain()) to better match the intent of the function and method syntax.
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::capitalizeAvailable since: v3.0.0-alpha.11
The string::capitalize function capitalizes the first letter of each word in a string.
API DEFINITIONstring::capitalize(string, ...) -> string
The following example shows this function, and its output, when used in a RETURN statement:
string::capitalize("how to cook for forty humans"); -- 'How To Cook For Forty Humans'
string::concatThe string::concat function concatenates strings together.
API DEFINITIONstring::concat(string, ...) -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::concat('this', ' ', 'is', ' ', 'a', ' ', 'test'); "this is a test"
string::containsThe string::contains function checks whether a string contains another string.
API DEFINITIONstring::contains(string, string) -> bool
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::contains('abcdefg', 'cde'); true
string::ends_withAvailable since: v2.0.0
NoteThis function was known as
string::endsWithin versions of SurrrealDB before 2.0. The behaviour has not changed.
The string::ends_with function checks whether a string ends with another string.
API DEFINITIONstring::ends_with(string, string) -> bool
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::ends_with('some test', 'test'); true
string::joinThe string::join function joins strings together with a delimiter. If you want to join an array of strings use array::join.
API DEFINITIONstring::join(string, string...) -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::join(', ', 'a', 'list', 'of', 'items'); "a, list, of, items"
string::lenThe string::len function returns the length of a given string.
API DEFINITIONstring::len(string) -> number
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::len('this is a test'); 14
string::lowercaseThe string::lowercase function converts a string to lowercase.
API DEFINITIONstring::lowercase(string) -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::lowercase('THIS IS A TEST'); "this is a test"
string::matchesThe string::matches function performs a regex match on a string.
API DEFINITIONstring::matches(string, string) -> bool
The following example shows this function, and its output, when used in a RETURN statement:
RETURN [ string::matches("grey", "gr(a|e)y"), string::matches("gray", "gr(a|e)y") ]; [ true, true ]
string::repeatThe string::repeat function repeats a string a number of times.
API DEFINITIONstring::repeat(string, number) -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::repeat('test', 3); "testtesttest"
string::replaceThe string::replace function replaces an occurrence of a string with another string.
API DEFINITIONstring::replace(string, string, string) -> string
API DEFINITIONstring::replace(string, string|regex, string) -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::replace('this is a test', 'a test', 'awesome'); "this is awesome"
With regexes added as a data type in version 2.3, the second argument can also be a regex instead of a string.
RETURN string::replace('Many languages only use consonants in their writing', <regex>'a|e|i|o|u', '');
Output'Mny lnggs nly s cnsnnts n thr wrtng'
string::reverseThe string::reverse function reverses a string.
API DEFINITIONstring::reverse(string) -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::reverse('this is a test'); "tset a si siht"
string::sliceThe string::slice function extracts and returns a section of a string.
API DEFINITIONstring::slice(string, number, number) -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::slice('this is a test', 10, 4); "test"
string::slugThe string::slug function converts a string into a human and URL-friendly string.
API DEFINITIONstring::slug(string) -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::slug('SurrealDB has launched #database #awesome'); "surrealdb-has-launched-database-awesome"
string::splitThe string::split function splits a string by a given delimiter.
API DEFINITIONstring::split(string, string) -> array
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::split('this, is, a, list', ', '); ["this", "is", "a", "list"]
string::starts_withAvailable since: v2.0.0
NoteThis function was known as
string::startsWithin versions of SurrrealDB before 2.0. The behaviour has not changed.
The string::starts_with function checks whether a string starts with another string.
API DEFINITIONstring::starts_with(string, string) -> bool
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::starts_with('some test', 'some'); true
string::trimThe string::trim function removes whitespace from the start and end of a string.
API DEFINITIONstring::trim(string) -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::trim(' this is a test '); "this is a test"
string::uppercaseThe string::uppercase function converts a string to uppercase.
API DEFINITIONstring::uppercase(string) -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::uppercase('this is a test'); "THIS IS A TEST"
string::wordsThe string::words function splits a string into an array of separate words.
API DEFINITIONstring::words(string) -> array
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::words('this is a test'); ["this", "is", "a", "test"]
string::distance::damerau_levenshteinAvailable since: v2.1.0
The string::distance::damerau_levenshtein function returns the Damerau-Levenshtein distance between two strings.
API DEFINITIONstring::distance::damerau_levenshtein(string, string) -> int
The following examples shows this function, and its output in comparison with a number of strings.
LET $first = "In a hole in the ground there lived a hobbit"; LET $same = "In a hole in the ground there lived a hobbit"; LET $close = "In a hole in the GROUND there lived a Hobbit"; LET $different = "A narrow passage holds four hidden treasures"; LET $short = "Hi I'm Brian"; -- Returns 0 string::distance::damerau_levenshtein($first, $same); -- Returns 7 string::distance::damerau_levenshtein($first, $close); -- Returns 34 string::distance::damerau_levenshtein($first, $different); -- Returns 38 string::distance::damerau_levenshtein($first, $short);
string::distance::normalized_damerau_levenshteinAvailable since: v2.1.0
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.
API DEFINITIONstring::distance::normalized_damerau_levenshtein(string, string) -> float
The following examples shows this function, and its output in comparison with a number of strings.
LET $first = "In a hole in the ground there lived a hobbit"; LET $same = "In a hole in the ground there lived a hobbit"; LET $close = "In a hole in the GROUND there lived a Hobbit"; LET $different = "A narrow passage holds four hidden treasures"; LET $short = "Hi I'm Brian"; -- Returns 1 string::distance::normalized_damerau_levenshtein($first, $same); -- Returns 0.8409090909090909f string::distance::normalized_damerau_levenshtein($first, $close); -- Returns 0.2272727272727273f string::distance::normalized_damerau_levenshtein($first, $different); -- Returns 0.13636363636363635f string::distance::normalized_damerau_levenshtein($first, $short);
string::distance::hammingAvailable since: v2.1.0
The string::distance::hamming function returns the Hamming distance between two strings of equal length.
API DEFINITIONstring::distance::hamming(string, string) -> int
The following examples shows this function, and its output in comparison with a number of strings.
LET $first = "In a hole in the ground there lived a hobbit"; LET $same = "In a hole in the ground there lived a hobbit"; LET $close = "In a hole in the GROUND there lived a Hobbit"; LET $different = "A narrow passage holds four hidden treasures"; LET $short = "Hi I'm Brian"; -- Returns 0 string::distance::hamming($first, $same); -- Returns 7 string::distance::hamming($first, $close); -- Returns 40 string::distance::hamming($first, $different); -- Error: strings must be of equal length string::distance::hamming($first, $short);
string::distance::levenshteinAvailable since: v2.1.0
The string::distance::levenshtein function returns the Levenshtein distance between two strings.
API DEFINITIONstring::distance::levenshtein(string, string) -> int
The following examples shows this function, and its output in comparison with a number of strings.
LET $first = "In a hole in the ground there lived a hobbit"; LET $same = "In a hole in the ground there lived a hobbit"; LET $close = "In a hole in the GROUND there lived a Hobbit"; LET $different = "A narrow passage holds four hidden treasures"; LET $short = "Hi I'm Brian"; -- Returns 0 string::distance::levenshtein($first, $same); -- Returns 7 string::distance::levenshtein($first, $close); -- Returns 35 string::distance::levenshtein($first, $different); -- Returns 38 string::distance::levenshtein($first, $short);
string::distance::normalized_levenshteinAvailable since: v2.1.0
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.
API DEFINITIONstring::distance::normalized_levenshtein(string, string) -> float
The following examples shows this function, and its output in comparison with a number of strings.
LET $first = "In a hole in the ground there lived a hobbit"; LET $same = "In a hole in the ground there lived a hobbit"; LET $close = "In a hole in the GROUND there lived a Hobbit"; LET $different = "A narrow passage holds four hidden treasures"; LET $short = "Hi I'm Brian"; -- Returns 1 string::distance::normalized_levenshtein($first, $same); -- Returns 0.8409090909090909f string::distance::normalized_levenshtein($first, $close); -- Returns 0.20454545454545459f string::distance::normalized_levenshtein($first, $different); -- Returns 0.13636363636363635f string::distance::normalized_levenshtein($first, $short);
string::distance::osaNoteThis function was known as
string::distance::osa_distancein versions of SurrrealDB before 3.0.0-alpha.8. The behaviour has not changed.
Available since: v2.1.0
The string::distance::osa function returns the OSA (Optimal String Alignment) distance between two strings.
API DEFINITIONstring::distance::normalized_levenshtein(string, string) -> int
The following examples shows this function, and its output in comparison with a number of strings.
LET $first = "In a hole in the ground there lived a hobbit"; LET $same = "In a hole in the ground there lived a hobbit"; LET $close = "In a hole in the GROUND there lived a Hobbit"; LET $different = "A narrow passage holds four hidden treasures"; LET $short = "Hi I'm Brian"; -- Returns 0 string::distance::osa($first, $same); -- Returns 7 string::distance::osa($first, $close); -- Returns 34 string::distance::osa($first, $different); -- Returns 38 string::distance::osa($first, $short);
string::html::encodeAvailable since: v2.0.0
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.
API DEFINITIONstring::html::encode(string) -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::html::encode("<h1>Safe Title</h1><script>alert('XSS')</script><p>Safe paragraph. Not safe <span onload='logout()'>event</span>.</p>"); ['<h1>Safe Title</h1><script>alert('XSS')</script><p>Safe paragraph. Not safe <span onload='logout()'>event</span>.</p>']
string::html::sanitizeAvailable since: v2.0.0
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.
API DEFINITIONstring::html::sanitize(string) -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::html::sanitize("<h1>Safe Title</h1><script>alert('XSS')</script><p>Safe paragraph. Not safe <span onload='logout()'>event</span>.</p>"); ['<h1>Safe Title</h1><p>Safe paragraph. Not safe <span>event</span>.</p>']
string::is_alphanumNoteThis function was known as
string::is::alphanumin versions of SurrrealDB before 3.0.0-alpha.8. The behaviour has not changed.
The string::is_alphanum function checks whether a value has only alphanumeric characters.
API DEFINITIONstring::is_alphanum(string) -> bool
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::is_alphanum("ABC123"); true
string::is_alphaNoteThis function was known as
string::is::alphain versions of SurrrealDB before 3.0.0-alpha.8. The behaviour has not changed.
The string::is_alpha function checks whether a value has only alpha characters.
API DEFINITIONstring::is_alpha(string) -> bool
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::is_alpha("ABCDEF"); true
string::is_asciiNoteThis function was known as
string::is::asciiin versions of SurrrealDB before 3.0.0-alpha.8. The behaviour has not changed.
The string::is_ascii function checks whether a value has only ascii characters.
API DEFINITIONstring::is_ascii(string) -> bool
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::is_ascii("ABC123"); true
string::is_datetimeNoteThis function was known as
string::is::datetimein versions of SurrrealDB before 3.0.0-alpha.8. The behaviour has not changed.
The string::is_datetime function checks whether a string representation of a date and time matches a specified format.
API DEFINITIONstring::is_datetime(string, string) -> bool
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::is_datetime("2015-09-05 23:56:04", "%Y-%m-%d %H:%M:%S");
Responsetrue
This can be useful when validating datetimes obtained from other sources that do not use the RFC 3339 format.
RETURN string::is_datetime("5sep2024pm012345.6789", "%d%b%Y%p%I%M%S%.f");
Responsetrue
RETURN string::is_datetime("23:56:00 2015-09-05", "%Y-%m-%d %H:%M");
Responsefalse
string::is_domainNoteThis function was known as
string::is::domainin versions of SurrrealDB before 3.0.0-alpha.8. The behaviour has not changed.
The string::is_domain function checks whether a value is a domain.
API DEFINITIONstring::is_domain(string) -> bool
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::is_domain("surrealdb.com"); true
string::is_emailNoteThis function was known as
string::is::emailin versions of SurrrealDB before 3.0.0-alpha.8. The behaviour has not changed.
The string::is_email function checks whether a value is an email.
API DEFINITIONstring::is_email(string) -> bool
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::is_email("info@surrealdb.com"); true
string::is_hexadecimalNoteThis function was known as
string::is::hexadecimalin versions of SurrrealDB before 3.0.0-alpha.8. The behaviour has not changed.
The string::is_hexadecimal function checks whether a value is hexadecimal.
API DEFINITIONstring::is_hexadecimal(string) -> bool
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::is_hexadecimal("ff009e"); true
string::is_ipNoteThis function was known as
string::is::ipin versions of SurrrealDB before 3.0.0-alpha.8. The behaviour has not changed.
Available since: v2.0.0
The string::is_ip function checks whether a value is an IP address.
API DEFINITIONstring::is_ip(string) -> bool
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::is_ip("192.168.0.1"); true
string::is_ipv4NoteThis function was known as
string::is::ipv4in versions of SurrrealDB before 3.0.0-alpha.8. The behaviour has not changed.
Available since: v2.0.0
The string::is_ipv4 function checks whether a value is an IP v4 address.
API DEFINITIONstring::is_ipv4(string) -> bool
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::is_ipv4("192.168.0.1"); true
string::is_ipv6NoteThis function was known as
string::is::ipv6in versions of SurrrealDB before 3.0.0-alpha.8. The behaviour has not changed.
Available since: v2.0.0
The string::is_ipv6 function checks whether a value is an IP v6 address.
API DEFINITIONstring::is_ipv6(string) -> bool
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::is_ipv6("2001:0db8:85a3:0000:0000:8a2e:0370:7334"); true
string::is_latitudeNoteThis function was known as
string::is::latitudein versions of SurrrealDB before 3.0.0-alpha.8. The behaviour has not changed.
The string::is_latitude function checks whether a value is a latitude value.
API DEFINITIONstring::is_latitude(string) -> bool
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::is_latitude("-0.118092"); true
string::is_longitudeNoteThis function was known as
string::is::longitudein versions of SurrrealDB before 3.0.0-alpha.8. The behaviour has not changed.
The string::is_longitude function checks whether a value is a longitude value.
API DEFINITIONstring::is_longitude(string) -> bool
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::is_longitude("51.509865"); true
string::is_numericNoteThis function was known as
string::is::numericin versions of SurrrealDB before 3.0.0-alpha.8. The behaviour has not changed.
The string::is_numericfunction checks whether a value has only numeric characters.
API DEFINITIONstring::is_numeric(string) -> bool
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::is_numeric("1484091748"); true
string::is_semverNoteThis function was known as
string::is::semverin versions of SurrrealDB before 3.0.0-alpha.8. The behaviour has not changed.
The string::is_semver function checks whether a value matches a semver version.
API DEFINITIONstring::is_semver(string) -> bool
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::is_semver("1.0.0"); true
string::is_ulidNoteThis function was known as
string::is::ulidin versions of SurrrealDB before 3.0.0-alpha.8. The behaviour has not changed.
The string::is_ulid function checks whether a string is a ULID.
API DEFINITIONstring::is_ulid(string) -> bool
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::is_ulid("01JCJB3TPQ50XTG32WM088NKJD"); true
string::is_urlNoteThis function was known as
string::is::urlin versions of SurrrealDB before 3.0.0-alpha.8. The behaviour has not changed.
The string::is_url function checks whether a value is a valid URL.
API DEFINITIONstring::is_url(string) -> bool
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::is_url("https://surrealdb.com"); true
string::is_recordNoteThis function was known as
string::is::recordin versions of SurrrealDB before 3.0.0-alpha.8. The behaviour has not changed.
The string::is_record function checks whether a string is a Record ID.
API DEFINITIONstring::is_record(string, option<string | table>) -> bool
NoteThe 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.
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::is_record("person:test"); -- true RETURN string::is_record("person:test", "person"); -- true RETURN string::is_record("person:test", "other"); -- false RETURN string::is_record("not a record id"); -- false
string::is_uuidNoteThis function was known as
string::is::uuidin versions of SurrrealDB before 3.0.0-alpha.8. The behaviour has not changed.
The string::is_uuid function checks whether a string is a UUID.
API DEFINITIONstring::is_uuid(string) -> bool
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::is_uuid("018a6680-bef9-701b-9025-e1754f296a0f"); true
string::semver::compareAvailable since: v1.2.0
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.
API DEFINITIONstring::semver::compare(string, string) -> number
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::semver::compare("1.0.0", "1.3.5"); -1
string::semver::majorAvailable since: v1.2.0
The string::semver::major function extracts the major number out of a semver string.
API DEFINITIONstring::semver::major(string) -> number
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::semver::major("3.2.6"); 3
string::semver::minorAvailable since: v1.2.0
The string::semver::minor function extracts the minor number out of a semver string.
API DEFINITIONstring::semver::minor(string) -> number
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::semver::minor("3.2.6"); 2
string::semver::patchAvailable since: v1.2.0
The string::semver::patch function extracts the patch number out of a semver string.
API DEFINITIONstring::semver::patch(string) -> number
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::semver::patch("3.2.6"); 6
string::semver::inc::majorAvailable since: v1.2.0
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.
API DEFINITIONstring::semver::inc::major(string) -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::semver::inc::major("1.2.3"); "2.0.0"
string::semver::inc::minorAvailable since: v1.2.0
The string::semver::inc::minor function increments the minor number of a semver string. As a result, the patch number is reset to zero.
API DEFINITIONstring::semver::inc::minor(string) -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::semver::inc::minor("1.2.3"); "1.3.0"
string::semver::inc::patchAvailable since: v1.2.0
The string::semver::inc::patch function increments the patch number of a semver string.
API DEFINITIONstring::semver::inc::patch(string) -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::semver::inc::patch("1.2.3"); "1.2.4"
string::semver::set::majorAvailable since: v1.2.0
The string::semver::set::major function sets the major number of a semver string without changing the minor and patch numbers.
API DEFINITIONstring::semver::set::major(string, number) -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::semver::set::major("1.2.3", 9); "9.2.3"
string::semver::set::minorAvailable since: v1.2.0
The string::semver::set::minor function sets the minor number of a semver string without changing the major and patch numbers.
API DEFINITIONstring::semver::set::minor(string, number) -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::semver::set::minor("1.2.3", 9); "1.9.3"
string::semver::set::patchAvailable since: v1.2.0
The string::semver::set::patch function sets the patch number of a semver string without changing the major and minor numbers.
API DEFINITIONstring::semver::set::patch(string, number) -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN string::semver::set::patch("1.2.3", 9); "1.2.9"
string::similarity::fuzzyAPI DEFINITIONstring::similarity::fuzzy(string, string) -> int
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.
-- returns 51 RETURN string::similarity::fuzzy("DB", "DB"); -- returns 47 RETURN string::similarity::fuzzy("DB", "db");
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.
-- returns 51 RETURN string::similarity::fuzzy("DB", "DB"); -- returns 2997 RETURN string::similarity::fuzzy( "SurrealDB Cloud Beta is now live! We are excited to announce that we are inviting users from the waitlist to join. Stay tuned for your invitation!", "SurrealDB Cloud Beta is now live! We are excited to announce that we are inviting users from the waitlist to join. Stay tuned for your invitation!" ); -- returns 151 despite nowhere close to exact match RETURN string::similarity::fuzzy( "SurrealDB Cloud Beta is now live! We are excited to announce that we are inviting users from the waitlist to join. Stay tuned for your invitation!", "Surreal" );
A longer example showing a comparison of similarity scores to one another:
LET $original = "SurrealDB"; LET $strings = ["SurralDB", "surrealdb", "DB", "Surreal", "real", "basebase", "eel", "eal"]; FOR $string IN $strings { LET $score = string::similarity::fuzzy($original, $string); IF $score > 0 { CREATE comparison SET of = $original + '\t' + $string, score = $score }; }; SELECT of, score FROM comparison ORDER BY score DESC;
Response[ { of: 'SurrealDB surrealdb', score: 187 }, { of: 'SurrealDB SurralDB', score: 165 }, { of: 'SurrealDB Surreal', score: 151 }, { of: 'SurrealDB real', score: 75 }, { of: 'SurrealDB eal', score: 55 }, { of: 'SurrealDB DB', score: 41 } ]
string::similarity::jaroAvailable since: v2.1.0
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.
API DEFINITIONstring::similarity::jaro(string, string) -> float
The following examples shows this function, and its output in comparison with a number of strings.
LET $first = "In a hole in the ground there lived a hobbit"; LET $same = "In a hole in the ground there lived a hobbit"; LET $close = "In a hole in the GROUND there lived a Hobbit"; LET $different = "A narrow passage holds four hidden treasures"; LET $short = "Hi I'm Brian"; -- Returns 1 string::similarity::jaro($first, $same); -- Returns 0.8218673218673219f string::similarity::jaro($first, $close); -- Returns 0.6266233766233765f string::similarity::jaro($first, $different); -- Returns 0.4379509379509379f string::similarity::jaro($first, $short);
string::similarity::jaro_winklerAvailable since: v2.1.0
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.
API DEFINITIONstring::similarity::jaro_winkler(string, string) -> float
The following examples shows this function, and its output in comparison with a number of strings.
LET $first = "In a hole in the ground there lived a hobbit"; LET $same = "In a hole in the ground there lived a hobbit"; LET $close = "In a hole in the GROUND there lived a Hobbit"; LET $different = "A narrow passage holds four hidden treasures"; LET $short = "Hi I'm Brian"; -- Returns 0 string::similarity::jaro_winkler($first, $same); -- Returns 0.8931203931203932f string::similarity::jaro_winkler($first, $close); -- Returns 0.6266233766233765f string::similarity::jaro_winkler($first, $different); -- Returns 0.4379509379509379f string::similarity::jaro_winkler($first, $short);
Available since: v2.0.0
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.
-- Traditional syntax string::is_alphanum("MyStrongPassword123"); -- Method chaining syntax "MyStrongPassword123".is_alphanum();
Responsetrue
This is particularly useful for readability when a function is called multiple times.
-- Traditional syntax string::concat( string::uppercase( string::replace( string::replace("I'll send you a check for the catalog", "ck", "que") , "og", "ogue") ) , "!!!!"); -- Method chaining syntax "I'll send you a check for the catalog" .replace("ck", "que") .replace("og", "ogue") .uppercase() .concat("!!!!");
Response'I'LL SEND YOU A CHEQUE FOR THE CATALOGUE!!!!'