String functions
String functions read and reshape text. Use them to clean inbound payloads, extract identifiers, normalize values before they reach a destination system, and build the exact string format a target expects.
_ is the input your expression receives in these examples. Refer to Input variables for more information.
FEATURE AVAILABILITY
WEL is currently available to select customers. Contact your Customer Success Representative to confirm whether it is available in your workspace.
Call a string function
Call a function directly, or pipe a value into it with >>:
upper(_.status)
_.status >> upperThe pipe form reads left to right, which makes it the better choice when you chain several steps:
_.email >> trim >> lowerThe piped value fills the function's first argument. Write any other arguments normally:
_.order_id >> starts_with?('SO-')STRINGS DON'T CONVERT AUTOMATICALLY
String functions require a String. Passing a number or a date raises E100. Wrap the value in String(...) first. Refer to the Data types documentation for details.
Check a string
The following functions return a Boolean. Use them in conditions, in filter_by, and to guard a step before it runs.
blank?
Returns true if the string is empty or contains only whitespace.
blank?(string)| Parameter | Description |
|---|---|
| string | The string to test. |
A whitespace-only string is blank
The following example tests a whitespace-only string:
Formula
blank?(' ')Output
trueA non-empty string isn't blank
The following example tests a non-empty string:
Formula
blank?('SO-1001')Output
falseempty?
Returns true if the value has no content. It works on a String, List, Map, or Binary value, and unlike blank?, it returns true for null.
empty?(value)| Parameter | Description |
|---|---|
| value | A string, list, map, binary value, or null. |
An empty string is empty
The following example tests an empty string:
Formula
empty?('')Output
trueNull is empty
The following example tests a null value:
Formula
empty?(null)Output
trueBLANK? OR EMPTY?
Use empty? when the field may be missing entirely, because it accepts null. Use blank? when the field is present but may contain only spaces. blank?(null) raises an error.
contains?
Returns true if the string contains the substring, using a case-sensitive comparison.
contains?(string, substring)| Parameter | Description |
|---|---|
| string | The string to search. |
| substring | The value to look for. |
A matching substring, same case
The following example tests a substring that matches case exactly:
Formula
contains?('Partner account', 'Partner')Output
trueA matching substring, different case
The following example tests a substring that matches except for case:
Formula
contains?('Partner account', 'partner')Output
falsestarts_with?
Returns true if the string begins with the prefix.
starts_with?(string, prefix)| Parameter | Description |
|---|---|
| string | The string to test. |
| prefix | The prefix to look for. |
A string starting with the given prefix
The following example tests a string that starts with the given prefix:
Formula
starts_with?('SO-1001', 'SO-')Output
trueends_with?
Returns true if the string ends with the suffix.
ends_with?(string, suffix)| Parameter | Description |
|---|---|
| string | The string to test. |
| suffix | The suffix to look for. |
A string ending with the given suffix
The following example tests a string that ends with the given suffix:
Formula
ends_with?('invoice.pdf', '.pdf')Output
truevalid_email?
Returns true if the string is a valid email address, as defined in RFC 5321 and RFC 5322.
valid_email?(string)| Parameter | Description |
|---|---|
| string | The address to validate. |
A valid email address
The following example tests a valid email address:
Formula
valid_email?('[email protected]')Output
trueAn address with a doubled @ is invalid
The following example tests an address with a doubled @:
Formula
valid_email?('nur@@example.com')Output
falsevalid_url?
Returns true if the string is a valid URL. Pass a list of schemes to restrict which are accepted.
valid_url?(string)
valid_url?(string, schemes)| Parameter | Description |
|---|---|
| string | The URL to validate. |
| schemes | Optional. A list of allowed schemes. |
A valid URL with no scheme restriction
The following example tests a valid URL with no scheme restriction:
Formula
valid_url?('https://example.com/orders')Output
trueA URL whose scheme isn't in the allowed list
The following example tests a URL whose scheme isn't in the allowed list:
Formula
valid_url?('ftp://example.com', ['http', 'https'])Output
falsematch?
Returns true if the string matches a regular expression. WEL uses ECMAScript regular expression syntax.
match?(string, pattern)| Parameter | Description |
|---|---|
| string | The string to test. |
| pattern | A regular expression. |
A string matching the pattern
The following example tests a string against a pattern it matches:
Formula
match?('SO-1001', '^SO-\d+$')Output
trueUse case: Filter a delimited recipient list
A webhook delivers recipients as one comma-separated string with inconsistent spacing, casing, and malformed entries. Use string functions to split it, normalize each address, then keep only the valid ones:
Input
{
"recipients": "[email protected], [email protected] ,,not-an-address"
}Formula
_.recipients
>> split(',')
>> map_by(e ~> trim(e) >> lower)
>> filter_by(e ~> valid_email?(e))Output
["[email protected]", "[email protected]"]split produces four entries, including one empty string. trim and lower normalize each one. valid_email? discards both the empty entry and not-an-address.
Change case
The following functions change the case of a string's characters:
upper
Converts the string to uppercase.
upper(string)| Parameter | Description |
|---|---|
| string | The string to convert. |
Convert a string to uppercase
The following example converts a string to uppercase:
Formula
upper('acme corp')Output
ACME CORPlower
Converts the string to lowercase. Use it to normalize email addresses and codes before comparing or deduplicating them.
lower(string)| Parameter | Description |
|---|---|
| string | The string to convert. |
Convert a string to lowercase
The following example converts a string to lowercase:
Formula
lower('ACME Corp')Output
acme corpcapitalize
Converts the first character to uppercase and the rest to lowercase.
capitalize(string)| Parameter | Description |
|---|---|
| string | The string to convert. |
Capitalize a lowercase word
The following example capitalizes a lowercase word:
Formula
capitalize('acme')Output
Acmetitleize
Converts the first character of each whitespace-separated word to uppercase and the rest to lowercase.
titleize(string)| Parameter | Description |
|---|---|
| string | The string to convert. |
Title-case a lowercase phrase
The following example title-cases a lowercase phrase:
Formula
titleize('acme widgets inc')Output
Acme Widgets IncClean and pad
The following functions remove whitespace or pad a string to a fixed width:
trim
Removes leading and trailing whitespace.
trim(string)| Parameter | Description |
|---|---|
| string | The string to trim. |
Trim whitespace from both ends
The following example trims whitespace from both ends of a string:
Formula
trim(' SO-1001 ')Output
SO-1001ltrim
Removes leading whitespace.
ltrim(string)| Parameter | Description |
|---|---|
| string | The string to trim. |
Trim whitespace from the start
The following example trims whitespace from the start of a string:
Formula
ltrim(' SO-1001')Output
SO-1001rtrim
Removes trailing whitespace.
rtrim(string)| Parameter | Description |
|---|---|
| string | The string to trim. |
Trim whitespace from the end
The following example trims whitespace from the end of a string:
Formula
rtrim('SO-1001 ')Output
SO-1001lpad
Pads the start of the string until it reaches the given width. Use it for zero-padded reference numbers and fixed-width records.
lpad(string, width, pad)| Parameter | Description |
|---|---|
| string | The string to pad. |
| width | The target width. |
| pad | The padding string. |
Zero-pad a number to a fixed width
The following example zero-pads a number to a fixed width:
Formula
lpad('42', 8, '0')Output
00000042rpad
Pads the end of the string until it reaches the given width.
rpad(string, width, pad)| Parameter | Description |
|---|---|
| string | The string to pad. |
| width | The target width. |
| pad | The padding string. |
Space-pad a string to a fixed width
The following example space-pads a string to a fixed width:
Formula
rpad('A-100', 8, ' ')Output
"A-100 "Padded to 8 characters.
normalize_newlines
Rewrites CRLF, CR, and LF line terminators to a single convention. Defaults to LF.
normalize_newlines(string, terminator)| Parameter | Description |
|---|---|
| string | The string to normalize. |
| terminator | Optional. The target line terminator. |
Normalize mixed line terminators to LF
The following example normalizes mixed line terminators to LF:
Formula
normalize_newlines("a\r\nb\rc")Output
"a\nb\nc"Use case: Build a fixed-width record
Many ERP and mainframe systems accept fixed-width records rather than JSON. Use string functions to pad each field to its column width, then concatenate them:
Input
{
"sku": "A-100",
"qty": 2
}Formula
rpad(_.sku, 10, ' ') ++ lpad(String(_.qty), 5, '0')Output
"A-100 00002"The SKU occupies a 10-character column padded on the right. The quantity occupies a 5-character column zero-padded on the left. qty is an Integer, so String(...) converts it before padding.
Extract part of a string
The following functions read or extract part of a string without changing the rest of it:
substring
Extracts part of a string by code-point index. A negative start counts back from the end.
substring(string, start, length)| Parameter | Description |
|---|---|
| string | The source string. |
| start | The zero-based start index. |
| length | Optional. The number of code points to take. |
Extract from a start index to the end
The following example extracts from a start index to the end of the string:
Formula
substring('SO-1001', 3)Output
1001Extract a fixed-length substring
The following example extracts a fixed-length substring:
Formula
substring('SO-1001', 0, 2)Output
SOExtract using a negative start index
The following example extracts using a negative start index counting back from the end:
Formula
substring('SO-1001', -4)Output
1001OUT-OF-RANGE STARTS RAISE E201
WEL clamps a length longer than the remaining string. A start past the end of the string raises E201. Check the length first when the start position isn't 0.
index_of
Returns the zero-based index of the first occurrence of a substring, or -1 if it isn't found.
index_of(string, substring)| Parameter | Description |
|---|---|
| string | The string to search. |
| substring | The value to find. |
Find the index of a substring
The following example finds the index of a substring:
Formula
index_of('orders/SO-1001', '/')Output
6split
Splits a string into a list on a literal separator.
split(string, separator)| Parameter | Description |
|---|---|
| string | The string to split. |
| separator | The literal separator. |
Split a string on a literal separator
The following example splits a string on a literal separator:
Formula
split('[email protected],[email protected]', ',')Output
["[email protected]", "[email protected]"]split_regex
Splits a string into a list on a regular expression. Use it when the delimiter varies.
split_regex(string, pattern)| Parameter | Description |
|---|---|
| string | The string to split. |
| pattern | A regular expression matching the separator. |
Split a string on a varying delimiter
The following example splits a string on a delimiter that varies between entries:
Formula
split_regex('A-100; B-220,C-050', '[;,]\s*')Output
["A-100", "B-220", "C-050"]match
Returns the first regular expression match as a map, or null if there is no match. Key 0 is the full match, numeric keys hold each capture group, and named captures are also available by name.
match(string, pattern)| Parameter | Description |
|---|---|
| string | The string to search. |
| pattern | A regular expression. |
Match a pattern with named capture groups
The following example matches a pattern with named capture groups:
Formula
match('SO-1001', '^(?<prefix>[A-Z]+)-(?<number>\d+)$')Output
{"0": "SO-1001", "1": "SO", "2": "1001", prefix: "SO", number: "1001"}NAME YOUR CAPTURE GROUPS
Named captures make a formula readable and keep it working when you add a group. Read the result as match(...).number rather than match(...)['2'].
match_all
Returns every regular expression match as a list of maps, using the same key structure as match.
match_all(string, pattern)| Parameter | Description |
|---|---|
| string | The string to search. |
| pattern | A regular expression. |
Match every occurrence of a pattern
The following example matches every occurrence of a pattern:
Formula
match_all('A-100 B-220', '[A-Z]-\d+')Output
[{"0": "A-100"}, {"0": "B-220"}]parse_url
Parses a URL into its components.
parse_url(string)| Parameter | Description |
|---|---|
| string | The URL to parse. |
Parse a URL into its components
The following example parses a URL into its components:
Formula
parse_url('https://api.example.com:8443/v2/orders?status=open#top')Output
{scheme: "https", host: "api.example.com", port: 8443, path: "/v2/orders", query: "status=open", fragment: "top"}Use case: Extract an identifier from a callback path
An inbound callback carries the order number inside a URL path. Use a named capture group to pull it out, without depending on the position of the segment:
Input
{
"path": "/orders/SO-1001/lines"
}Formula
match(_.path, '/orders/(?<order>[A-Z]{2}-\d+)/').orderOutput
"SO-1001"match returns a map, so the formula reads the order key directly. match returns null if the path can't match, and reading the key then fails as a result. Add a fallback with |? when the source data varies. Refer to the Operators documentation for details.
Replace part of a string
WEL has separate functions for literal and regular expression matching. Each comes in a first-match and an all-matches form.
| Function | Matches | Replaces |
|---|---|---|
replace_first | Literal text | First occurrence |
replace_all | Literal text | All occurrences |
replace_first_regex, sub | Regular expression | First match |
replace_all_regex, gsub | Regular expression | All matches |
replace_all
Replaces every occurrence of a literal substring.
replace_all(string, pattern, replacement)| Parameter | Description |
|---|---|
| string | The source string. |
| pattern | The literal text to find. |
| replacement | The replacement text. |
Remove every occurrence of a literal substring
The following example removes every occurrence of a literal substring:
Formula
replace_all('A-100-X', '-', '')Output
A100Xreplace_first
Replaces the first occurrence of a literal substring.
replace_first(string, pattern, replacement)| Parameter | Description |
|---|---|
| string | The source string. |
| pattern | The literal text to find. |
| replacement | The replacement text. |
Remove the first occurrence of a literal substring
The following example removes the first occurrence of a literal substring:
Formula
replace_first('A-100-X', '-', '')Output
A100-Xreplace_all_regex
Replaces every regular expression match. gsub is an alias.
replace_all_regex(string, pattern, replacement)| Parameter | Description |
|---|---|
| string | The source string. |
| pattern | A regular expression. |
| replacement | The replacement text. |
Collapse repeated whitespace to a single space
The following example collapses repeated whitespace into a single space:
Formula
replace_all_regex('SO 1001 extra', '\s+', ' ')Output
SO 1001 extraStrip non-digit characters using the gsub alias
The following example strips every non-digit character using the gsub alias:
Formula
gsub('(555) 123-4567', '[^0-9]', '')Output
5551234567replace_first_regex
Replaces the first regular expression match. sub is an alias.
replace_first_regex(string, pattern, replacement)| Parameter | Description |
|---|---|
| string | The source string. |
| pattern | A regular expression. |
| replacement | The replacement text. |
Replace the first regex match using the sub alias
The following example replaces the first regular expression match using the sub alias:
Formula
sub('SO-1001', '^SO', 'PO')Output
PO-1001concat
Joins two strings. Use ++ or string interpolation to join more than two, or to mix in other types.
concat(first, second)| Parameter | Description |
|---|---|
| first | The first string. |
| second | The second string. |
Join two strings
The following example joins two strings:
Formula
concat('Josh', ' Ito')Output
Josh ItoCONCAT TAKES EXACTLY TWO ARGUMENTS
concat isn't variadic. Use ++ to join several values, or interpolation to embed them in a template:
_.first_name ++ ' ' ++ _.last_name
"Order ${_.order_id} for ${_.customer}"Interpolation converts values to strings automatically. ++ doesn't. Refer to the Strings and formatting documentation for details.
Use case: Normalize an inbound contact
A signup webhook delivers names with inconsistent spacing and casing, and an email address that a downstream CRM treats as case-sensitive. Use string functions to normalize all three fields before the record is created:
Input
{
"first_name": " josh ",
"last_name": "ITO",
"email": " [email protected] "
}Formula
{
full_name: titleize(trim(_.first_name) ++ ' ' ++ trim(_.last_name)),
email: lower(trim(_.email))
}Output
{
"full_name": "Josh Ito",
"email": "[email protected]"
}trim removes whitespace from each field before ++ joins them, so the joining space is the only space between the names. titleize then fixes the casing of both names at once. lower normalizes the address so it matches an existing CRM record regardless of how it was typed.
Related
- Data types: Why string functions require a
String. - Strings and formatting: Information about interpolation, f-strings, and format specs.
- Operators: Information about
++, the pipe>>, and the fallback operators. - Error codes: Troubleshoot job failures such as
E100andE201.
Last updated: