Skip to main content
WireMock Cloud provides a set of string manipulation helpers.

Regular expression extract

The regexExtract helper supports extraction of values matching a regular expression from a string. A single value can be extracted like this:
Regex groups can be used to extract multiple parts into an object for later use (the last parameter is a variable name to which the object will be assigned):
Optionally, a default value can be specified for when there is no match. When the regex does not match and no default is specified, an error will be thrown instead.

Regular expression replace

The regexReplace helper replaces all matches of a regular expression in a string with a replacement value.
Capture groups in the pattern can be referenced in the replacement using $1, $2 etc:

String transformation helpers

Trim

Use the trim helper to remove whitespace from the start and end of the input:

Abbreviate

abbreviate truncates a string if it is longer than the specified number of characters. Truncated strings will end with a translatable ellipsis sequence (”…”). For instance the following template:

Capitalisation

capitalize will make the first letter of each word in the passed string a capital e.g.
capitalizeFirst will capitalise the first character of the value passed e.g.

Center

center centers the value in a field of a given width e.g.
will output:
You can also specify the padding character e.g.
will output:

Cut

cut removes all instances of the parameter from the given string.

Default if empty

defaultIfEmpty outputs the passed value if it is not empty, or the default otherwise e.g.

Join

join takes a set of parameters or a collection and builds a single string, with each item separated by the specified parameter.
You can optionally specify a prefix and suffix:

Justify left and right

ljust left-aligns the value in a field of a given width, optionally taking a padding character.
rjust right-aligns the value in the same manner

Lower and upper case

lower and upper convert the value to all lowercase and all uppercase:

Replace

replace replaces all occurrences of the specified substring with the replacement value.

Slugify

slugify converts to lowercase, removes non-word characters (alphanumerics and underscores) and converts spaces to hyphens. Also strips leading and trailing whitespace.

Split

split divides a string into a list of substrings using the given delimiter. The delimiter is treated as a literal string, not a regular expression.
The result can be used with other helpers that accept collections, such as arrayJoin:

Strip tags

stripTags strips all [X]HTML tags.

Substring

substring outputs the portion of a string value between two indices. If only one index is specified the substring between this point and the end will be returned.

Word wrap

wordWrap wraps words at specified line length.
will output:

Yes/no

yesno maps values for true, false and optionally null, to the strings “yes”, “no”, “maybe”.
You can also specify different strings to represent each state: