String Verbs
All string verbs take a text value and return a new value — strings in OQL are immutable. String delimiters are interchangeable: double quotes, single quotes, and backticks all produce identical tokens.
| Verb | Description |
|---|---|
UPPER "text" | Uppercase |
LOWER "text" | Lowercase |
UCWORDS "text" | Title-case — first letter of each word capitalised |
TRIM STRING "text" / TRIM "text" | Remove leading and trailing whitespace. Both forms are identical. |
LENGTH "text" | Character count. On an array returns element count. On binary returns byte count. |
REVERSE STRING "text" | Reverse character order of a string. |
REPLACE "text" WHERE "find" WITH "repl" | Replace all literal occurrences |
REPLACE "text" WHERE "pattern" WITH "repl" AS "regex" | Regex replace — all occurrences. No first-only form exists. |
REPLACE "text" FROM n TO n WITH "repl" | Positional replace — equivalent to substr_replace |
SPLIT "text" WITH "delim" | Split into array on delimiter |
JOIN ?array WITH "delim" | Join array into string |
PAD "text" TO n | Left-pad to n chars with spaces (default) |
PAD "text" TO n WITH "char" AS "left"|"right"|"both" | WITH is the pad character. AS is direction. Default: left-pad with space. |
SLICE "text" FROM n TO n | Substring. FROM inclusive, TO exclusive. Also works on arrays. |
CONTAINS "text" WHERE "needle" | Returns boolean |
STARTS "text" WHERE "prefix" | Returns boolean |
ENDS "text" WHERE "suffix" | Returns boolean |
INDEX "text" WHERE "needle" | 0-based position of needle. Returns null if not found. |
REPLICATE "text" WITH n | Repeat string n times |
CHARS "text" | Split into array of single characters |
WORDS "text" | Split on whitespace into array of words |
MATCH "text" WHERE "pattern" | Regex — first match as text. Errors if no match. |
MATCH "text" WHERE "pattern" AS "all" | Regex — all matches as array. Errors if no match. |
STRING ?val | Coerce any value to its text representation |
UPPER / LOWER / UCWORDS
UPPER "hello world" SET ?u
AFTER LOWER "HELLO WORLD" SET ?l
AFTER UCWORDS "the quick brown fox" SET ?t
AFTER EMIT ?u & " | " & ?l & " | " & ?t
Try it ›
TRIM STRING / TRIM
TRIM STRING " hello world " SET ?t
AFTER EMIT "|" & ?t & "|"
Try it ›
(* Both forms are identical *)
TRIM " hello world " SET ?t
AFTER EMIT "|" & ?t & "|"
Try it ›
LENGTH
LENGTH "Engineering Magic" SET ?n
AFTER EMIT ?n
(* → 18 *)
Try it ›
(* On an array — element count *)
SPLIT "a,b,c,d" WITH "," SET ?arr
AFTER LENGTH ?arr SET ?n
AFTER EMIT ?n
(* → 4 *)
Try it ›
REVERSE STRING
REVERSE STRING "Engineering Magic" SET ?r
AFTER EMIT ?r
Try it ›
REPLACE — literal, regex, positional
(* Literal — replaces all occurrences *)
REPLACE "hello world world" WHERE "world" WITH "OQL" SET ?r
AFTER EMIT ?r
(* → "hello OQL OQL" *)
Try it ›
(* Regex — AS "regex" enables pattern matching *)
REPLACE "foo123bar456baz789" WHERE "[0-9]+" WITH "N" AS "regex" SET ?r
AFTER EMIT ?r
(* → "fooNbarNbazN" *)
Try it ›
(* Positional — FROM start TO end, equivalent to substr_replace *)
REPLACE "Hello World" FROM 6 TO 11 WITH "OQL" SET ?r
AFTER EMIT ?r
(* → "Hello OQL" *)
Try it ›
SPLIT / JOIN
SPLIT "red,green,blue" WITH "," SET ?colors
AFTER JOIN ?colors WITH " | " SET ?joined
AFTER EMIT ?joined
(* → "red | green | blue" *)
Try it ›
(* Split on any delimiter *)
SPLIT "one::two::three" WITH "::" SET ?parts
AFTER EMIT ?parts
Try it ›
PAD
TO is the target length. WITH is the pad character (default: space). AS is the direction: "left" (default), "right", or "both".
PAD "7" TO 4 WITH "0" SET ?l (* "0007" — left-pad, default *)
AFTER PAD "7" TO 4 WITH "0" AS "right" SET ?r (* "7000" — right-pad *)
AFTER PAD "7" TO 5 WITH "-" AS "both" SET ?b (* "--7--" — both sides *)
AFTER EMIT ?l & " | " & ?r & " | " & ?b
Try it ›
(* Practical: zero-pad an invoice number *)
PAD "42" TO 6 WITH "0" SET ?inv
AFTER EMIT "INV-" & ?inv
(* → "INV-000042" *)
Try it ›
SLICE
FROM is inclusive, TO is exclusive. Works on strings and arrays.
SLICE "Engineering Magic" FROM 0 TO 11 SET ?s
AFTER EMIT ?s
(* → "Engineering" *)
Try it ›
(* Array slice *)
SPLIT "a,b,c,d,e" WITH "," SET ?arr
AFTER SLICE ?arr FROM 1 TO 4 SET ?mid
AFTER EMIT ?mid
(* → ["b","c","d"] *)
Try it ›
CONTAINS / STARTS / ENDS / INDEX
CONTAINS "Engineering Magic" WHERE "Magic" SET ?has
AFTER STARTS "Engineering Magic" WHERE "Eng" SET ?sw
AFTER ENDS "Engineering Magic" WHERE "Magic" SET ?ew
AFTER INDEX "Engineering Magic" WHERE "Magic" SET ?pos
AFTER EMIT "contains=" & ?has & " starts=" & ?sw & " ends=" & ?ew & " pos=" & ?pos
Try it ›
(* INDEX returns null when needle is not found *)
INDEX "hello" WHERE "xyz" SET ?pos
AFTER IF ?pos IS NULL
OPEN NEST EMIT "not found" CLOSE NEST
Try it ›
REPLICATE
REPLICATE "ab" WITH 4 SET ?r
AFTER EMIT ?r
(* → "abababab" *)
Try it ›
CHARS / WORDS
CHARS "hello" SET ?c
AFTER EMIT ?c
(* → ["h","e","l","l","o"] *)
Try it ›
WORDS "the quick brown fox" SET ?w
AFTER EMIT ?w
(* → ["the","quick","brown","fox"] *)
Try it ›
MATCH — regex extraction
(* First match only *)
MATCH "Call us on +27 21 555 0123 or +27 11 999 8888" WHERE "\+[0-9 ]+" SET ?phone
AFTER EMIT ?phone
(* → "+27 21 555 0123" *)
Try it ›
(* All matches — AS "all" returns array *)
MATCH "prices: $10 $25 $99" WHERE "\$[0-9]+" AS "all" SET ?prices
AFTER EMIT ?prices
(* → ["$10","$25","$99"] *)
Try it ›
(* Extract emails from a block of text *)
MATCH "Contact alice@example.com or bob@company.co.za" WHERE "[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}" AS "all" SET ?emails
AFTER EMIT ?emails
Try it ›
STRING — coerce to text
STRING 42 SET ?a (* → "42" *)
AFTER STRING true SET ?b (* → "true" *)
AFTER STRING 3.14 SET ?c (* → "3.14" *)
AFTER EMIT ?a & " " & ?b & " " & ?c
Try it ›
(* Coerce an object to its JSON text representation *)
NEW JSON OBJECT OPEN NEST SET "name" AS "OQL" CLOSE NEST SET ?obj
AFTER STRING ?obj SET ?s
AFTER EMIT ?s
Try it ›
String pipeline — combining verbs
(* Clean user input: trim, lowercase, replace spaces with dashes *)
TRIM STRING " Hello World " SET ?clean
AFTER LOWER ?clean SET ?lower
AFTER REPLACE ?lower WHERE " " WITH "-" SET ?slug
AFTER EMIT ?slug
(* → "hello-world" *)
Try it ›
(* Parse a CSV line, trim each value, rejoin *)
SPLIT " Alice , 30 , Cape Town " WITH "," SET ?parts
AFTER FOREACH ?parts AS ?part
OPEN NEST
TRIM STRING ?part SET ?trimmed
AFTER EMIT ?trimmed
CLOSE NEST
Try it ›