String Function Expressions
This example shows how to use string functions within expressions.
The following string functions are supported:
replace(searchRegexp, replacement)
: Replaces the first occurrence of a pattern matching the regular expression with a replacement string. SeeString.prototype.replace()
.replaceAll(searchRegexp, replacement)
: Replaces all occurrences of a pattern matching the regular expression with a replacement string. SeeString.prototype.replaceAll()
.slice(start, end)
: Extracts a section of a string and returns it as a new string, without modifying the original string. SeeString.prototype.slice()
.substring(start, end)
: Returns the part of the string between the start and end indexes, or to the end of the string. SeeString.prototype.substring()
.trimStart()
: Removes whitespace from the beginning of a string. SeeString.prototype.trimStart()
.trimEnd()
: Removes whitespace from the end of a string. SeeString.prototype.trimEnd()
.trim()
: Removes whitespace from both ends of a string. SeeString.prototype.trim()
.toUpperCase()
: Converts a string to uppercase letters. SeeString.prototype.toUpperCase()
.toLowerCase()
: Converts a string to lowercase letters. SeeString.prototype.toLowerCase()
.
👉 Edit this example in the playground.
- Config
- Script
{
"description": "This example demonstrates how to use string function expressions in the configuration.",
"global": {
"thread": {
"match": {
"query": "-in:trash -in:drafts -in:spam from:{{user.email}} to:{{user.email}} after:{{date.now|formatDate('yyyy-MM-dd')}} is:unread subject:\"[GmailProcessor-Test] stringFnExpressions\""
}
}
},
"settings": {
"markProcessedMethod": "mark-read",
"logSensitiveRedactionMode": "none"
},
"threads": [
{
"match": {
"query": ""
},
"messages": [
{
"actions": [
{
"name": "global.log",
"args": {
"message": "Removing '[]' from subject: {{message.subject|replaceAll('[\\[\\]]', '')}}"
}
}
]
}
]
}
]
}
function stringFnExpressionsRun() {
const config = {
description:
"This example demonstrates how to use string function expressions in the configuration.",
global: {
thread: {
match: {
query:
"-in:trash -in:drafts -in:spam from:{{user.email}} to:{{user.email}} after:{{date.now|formatDate('yyyy-MM-dd')}} is:unread subject:\"[GmailProcessor-Test] stringFnExpressions\"",
},
},
},
settings: {
markProcessedMethod: "mark-read",
logSensitiveRedactionMode: "none",
},
threads: [
{
match: {
query: "",
},
messages: [
{
actions: [
{
name: "global.log",
args: {
message:
"Removing '[]' from subject: {{message.subject|replaceAll('[\\[\\]]', '')}}",
},
},
],
},
],
},
],
}
return GmailProcessorLib.run(config, "dry-run")
}
Source: stringFnExpressions.ts | PRs: #556 | Discussions: #549