String Functions
20+ string manipulation functions including fuzzy matching, phonetic algorithms, and text processing.
STARTS_WITH(str, prefix)
Check if string starts with prefix.
RETURN STARTS_WITH("hello", "he") --true
ENDS_WITH(str, suffix)
Check if string ends with suffix.
RETURN ENDS_WITH("file.txt", ".txt") --true
PAD_LEFT(str, len, char?)
Pad string from left. Alias: LPAD.
RETURN PAD_LEFT("42", 5, "0") --"00042"
TITLE_CASE(str)
Title case all words. Alias: INITCAP.
RETURN TITLE_CASE("hello world") --"Hello World"
ENCODE_URI(str)
URL encode string. Alias: URL_ENCODE.
RETURN ENCODE_URI("hello world") --"hello%20world"
DECODE_URI(str)
URL decode string. Alias: URL_DECODE.
RETURN DECODE_URI("hello%20world") --"hello world"
TRUNCATE_TEXT(str, len, suffix?)
Truncate with ellipsis. Alias: ELLIPSIS.
RETURN TRUNCATE_TEXT("Hello World", 8) --"Hello..."
MASK(str, start?, end?, char?)
Mask string for PII protection.
RETURN MASK("4111111111111111", 0, -4) --"************1111"
LEFT(str, n) / RIGHT(str, n)
Extracts n characters from start or end.
RETURN LEFT("Hello", 2) --"He"
TRIM(val, type?/chars?)
Trims whitespace or chars. type: 0=both, 1=left, 2=right.
RETURN TRIM(" foo ") --"foo"
RETURN TRIM("--foo--", "-") --"foo"
SPLIT(val, sep, limit?)
Splits string into array.
RETURN SPLIT("foo-bar-baz", "-") --["foo", "bar", "baz"]
SUBSTITUTE(val, search, replace, limit?)
Replaces occurrences of search with replace.
RETURN SUBSTITUTE("foobar", "foo", "baz") --"bazbar"
CONTAINS(text, search, returnIndex?)
Checks if search string is in text. Returns boolean or index.
RETURN CONTAINS("foobar", "bar") --true
RETURN CONTAINS("foobar", "bar", true) --3
FIND_FIRST(str, search) / FIND_LAST
Returns index of first/last occurrence.
RETURN FIND_FIRST("hello", "l") --2
REGEX_TEST(str, pattern)
Tests if string matches regex. Alias: REGEX_MATCH.
RETURN REGEX_TEST("abc", "a.*") --true
REGEX_REPLACE(text, pattern, replacement)
Replace occurrences of a pattern in a string.
RETURN REGEX_REPLACE("the quick brown fox", "the (.*) fox", "a $1 dog")
Fuzzy Matching & Similarity
SIMILARITY(s1, s2)
Returns trigram similarity score (0.0 to 1.0).
RETURN SIMILARITY("hello", "hello") --1.0
RETURN SIMILARITY("hello", "hallo") --~0.6
FUZZY_MATCH(text, pattern, max_distance?)
Returns true if text matches pattern within edit distance. Default max_distance is 2.
RETURN FUZZY_MATCH("hello", "hello", 0) --true
RETURN FUZZY_MATCH("hello", "hallo", 1) --true
RETURN FUZZY_MATCH("jonathan", "jonathen") --true (default distance 2)
FOR doc IN users
FILTER FUZZY_MATCH(doc.name, @search, 2)
RETURN doc
Phonetic Functions
SOUNDEX(str, locale?)
Returns phonetic code for name matching. Supports locales: en, de, fr, es, it, pt, nl, el, ja.
-- English (default)
RETURN SOUNDEX("Smith") == SOUNDEX("Smyth") --true
-- German (de) - Cologne Phonetic
RETURN SOUNDEX("Mueller", "de") == SOUNDEX("Muller", "de") --true
-- French (fr)
RETURN SOUNDEX("Dupont", "fr") == SOUNDEX("Dupon", "fr") --true
METAPHONE(str)
Returns phonetic encoding using Metaphone algorithm.
RETURN METAPHONE("Katherine") --"K0RN"
RETURN METAPHONE("Wright") == METAPHONE("Right") --true
DOUBLE_METAPHONE(str)
Returns array with [primary, secondary] phonetic codes.
RETURN DOUBLE_METAPHONE("Schmidt") --["SMT", "SMT"]
COLOGNE(str)
Cologne Phonetic algorithm for German names.
RETURN COLOGNE("Mueller") == COLOGNE("Muller") --true
Text Transformation
Functions for transforming and sanitizing text input for URLs, forms, and security.
SLUGIFY URL-Friendly Slug Generation
Converts text to a URL-friendly slug: lowercase, spaces become hyphens, special characters removed.
SLUGIFY(text)
Basic Usage
RETURN SLUGIFY("Hello World!")
-- "hello-world"
RETURN SLUGIFY("My Blog Post Title")
-- "my-blog-post-title"
Special Characters
RETURN SLUGIFY("Café & Restaurant")
-- "cafe-restaurant"
RETURN SLUGIFY("Product #42: 50% Off!")
-- "product-42-50-off"
Use in Insert
INSERT {
title: @title,
slug: SLUGIFY(@title),
content: @content
} INTO articles
SANITIZE Input Sanitization
Cleans and sanitizes input strings using one or more operations. Supports chaining multiple sanitization options.
SANITIZE(text, options?)
Available Options
"trim"- Remove leading/trailing whitespace (default)"lowercase"/"lower"- Convert to lowercase"uppercase"/"upper"- Convert to uppercase"alphanumeric"/"alnum"- Keep only letters and numbers"alpha"- Keep only letters"numeric"/"digits"- Keep only numbers (and . -)"email"- Sanitize email (lowercase, valid chars only)"url"- Keep only URL-safe characters"html"- Escape HTML entities"strip_html"- Remove HTML tags"normalize"- Collapse multiple spaces to single space
Single Option
RETURN SANITIZE(" Hello ")
-- "Hello" (default: trim)
RETURN SANITIZE("Hello World", "uppercase")
-- "HELLO WORLD"
RETURN SANITIZE("abc123!@#", "alphanumeric")
-- "abc123"
Multiple Options (Array)
RETURN SANITIZE(" [email protected] ", ["trim", "lowercase"])
-- "[email protected]"
RETURN SANITIZE(" John Doe ", ["trim", "normalize"])
-- "John Doe"
Security Sanitization
RETURN SANITIZE("<script>alert('xss')</script>", "strip_html")
-- "alert('xss')"
RETURN SANITIZE("<b>Bold</b> text", "html")
-- "<b>Bold</b> text"
Form Input Sanitization
INSERT {
email: SANITIZE(@email, "email"),
name: SANITIZE(@name, ["trim", "normalize"]),
phone: SANITIZE(@phone, "numeric"),
bio: SANITIZE(@bio, ["trim", "strip_html"])
} INTO users
Security Best Practice
Always sanitize user input before storing. Use "html" to escape output displayed in HTML, or "strip_html" to remove tags entirely. Combine with validation for defense in depth.