String Functions
Concat
Appends all the arguments end to end in a single string
concat(args...)
Example
concat('this ', 'is ', 'how ', 'it ', 'works')
> 'this is how it works'
Contains
Tests if inputString contains subString.
contains(inputString, subString)
Example
contains('this', 'this')
> true
contains('this', 'that')
> false
Decode
The arguments are split into 3 parts
- The input value to test
- Pairs of regex matchers with their respective output value. Output values in the format ‘$n’ can be used to return the appropriate capture group value from the regex
- A default result, if the input doesn’t match any of the regexes.
decode(input, test1, result1, test2, result2, ... testN, resultN, otherwise)
It works much like a Java Switch/Case statement
Example
decode(${val}, 'red', 'rgb(255, 0, 0)', 'green', 'rgb(0, 255, 0)', 'blue', 'rgb(0, 0, 255)', 'rgb(255, 255, 255)')
${val}='blue'
> rgb(0, 0, 255)
${val}='green'
> rgb(0, 255, 0)
${val}='brown'
> rgb(255, 255, 255) // falls back to the 'otherwise' value
In Java, this would be equivalent to
String decode(value) {
switch(value) {
case "red":
return "rgb(255, 0, 0)"
case "green":
return "rgb(0, 255, 0)"
case "blue":
return "rgb(0, 0, 255)"
default:
return "rgb(255, 255, 255)"
}
}
decode('red')
> 'rgb(255, 0, 0)'
DecodeUrl
Decodes a URL
decodeUrl('userId%3Duser1')
> userId=user1
EncodeUrl
Encodes a URL
encodeUrl('userId=user1')
> userId%3Duser1
Exclude
If the supplied string matches one of the supplied match strings then return null, otherwise return the supplied string
exclude(aString, match...)
Example
exclude('hello', 'hello', 'hi')
> null
exclude('hi', 'hello', 'hi')
> null
exclude('bye', 'hello', 'hi')
> 'bye'
Hash
Cryptographically hashes a string
hash(value)
hash(value, algorithm)
hash(value, algorithm, salt)
Example
hash(${val}, 'SHA-512', 'mysalt')
> A hashed result...
If not specified the hash() function will use the SHA-256 algorithm.
Supported algorithms are determined by Java runtime environment.
HostAddress
Returns the host address (IP) for the given host string.
hostAddress(host)
Example
hostAddress('google.com')
> '142.251.29.102'
HostName
Returns the host name for the given host string.
hostName(host)
Example
hostName('142.251.29.102')
> 'google.com'
Include
If the supplied string matches one of the supplied match strings then return it, otherwise return null
include(aString, match...)
Example
include('hello', 'hello', 'hi')
> 'hello'
include('hi', 'hello', 'hi')
> 'hi'
include('bye', 'hello', 'hi')
> null
Index Of
Finds the first position (zero based) of subString in inputString or -1 if it cannot be found.
Uses a simple literal match.
indexOf(inputString, subString)
Example
indexOf('aa-bb-cc', '-')
> 2
Jq
Extracts values from a JSON string using a JQ expression.
jq(json, jq)
jq(json, jq, delimiter)
json- The JSON string to evaluate.jq- The JQ expression to use for extraction.delimiter- The delimiter to insert between the values of each matched element. Defaults to no delimiter.
Where the expression matches more than one element, the string values of all the matched elements are concatenated.
A value node contributes its raw value, and an object or array contributes its JSON form.
If nothing is matched then null is returned.
Example
jq('{"user":{"id":"jbloggs"}}', '.user.id')
> 'jbloggs'
jq('{"ids":["a","b","c"]}', '.ids[]')
> 'abc'
jq('{"ids":["a","b","c"]}', '.ids[]', ', ')
> 'a, b, c'
Last Index Of
Finds the last position (zero based) of subString in inputString or -1 if it cannot be found.
Uses a simple literal match.
lastIndexOf(inputString, subString)
Example
lastIndexOf('aa-bb-cc', '-')
> 5
Lower Case
Converts the string to lower case
lowerCase(aString)
Example
lowerCase('Hello DeVeLoPER')
> 'hello developer'
Match
Test an input string using a regular expression to see if it matches
match(input, regex)
Example
match('this', 'this')
> true
match('this', 'that')
> false
Param
Fetches the value of a named query parameter, or null() if the key cannot be found.
param(paramKey)
paramKey- The parameter key name to fetch the value for.
Examples
param('user')
> 'jbloggs'
Params
Returns all the query parameters for the current query as a space delimited string.
params()
Examples
params()
> 'user=jbloggs site=HQ'
Replace
Perform text replacement on an input string using a regular expression to match part (or all) of the input string and a replacement string to insert in place of the matched part
replace(input, regex, replacement)
Example
replace('this', 'is', 'at')
> 'that'
String Length
Takes the length of a string
stringLength(aString)
Example
stringLength('hello')
> 5
Substring
Take a substring based on start/end index of letters
substring(aString, startIndex, endIndex)
Example
substring('this', 1, 2)
> 'h'
Substring After
Get the substring from the first string that occurs after the presence of the second string
substringAfter(firstString, secondString)
Example
substringAfter('aa-bb', '-')
> 'bb'
Substring Before
Get the substring from the first string that occurs before the presence of the second string
substringBefore(firstString, secondString)
Example
substringBefore('aa-bb', '-')
> 'aa'
Upper Case
Converts the string to upper case
upperCase(aString)
Example
upperCase('Hello DeVeLoPER')
> 'HELLO DEVELOPER'
XPath
Extracts values from an XML string using an XPath 3.1 expression.
xpath(xml, xpath)
xpath(xml, xpath, namespaces)
xpath(xml, xpath, namespaces, delimiter)
xml- The XML string to evaluate.xpath- The XPath expression to use for extraction.namespaces- A space delimited list of namespace prefix to URI mappings, in the formprefix:uri prefix2:uri2. A mapping with no prefix, e.g.:uri, sets the default element namespace. If this argument is omitted or empty then namespaces in the XML are ignored.delimiter- The delimiter to insert between the values of each matched item. Defaults to no delimiter.
The string values of all the items matched by the expression are concatenated in document order. If nothing is matched then an empty string is returned.
If no namespace mappings are supplied then the XML is treated as being namespace unaware, i.e. element and attribute names are matched on their local name only. This means a document with a default namespace can be queried without having to declare it.
Example
xpath('<user><id>jbloggs</id></user>', '/user/id')
> 'jbloggs'
xpath('<users><id>jbloggs</id><id>jdoe</id></users>', '/users/id', '', ', ')
> 'jbloggs, jdoe'
xpath('<u:user xmlns:u="users:1"><u:id>jbloggs</u:id></u:user>', '/u:user/u:id', 'u:users:1')
> 'jbloggs'