TrimPrefix
less than a minute
Overview
The TrimPrefix converter removes a specified prefix from the beginning of a string. If the string does not start with the prefix, it is returned unchanged.
Syntax
TrimPrefix(target, prefix)
- target: the string to trim
- prefix: the prefix string to remove
Examples
Input
{
"_type": "log",
"body": {
"url": "https://api.example.com/v2/users",
"path": "report_2026_final.csv"
},
"resource": {...},
"attributes": {}
}
Statement
set(attributes["trimmed_url"], TrimPrefix(body["url"], "https://"))
set(attributes["no_match"], TrimPrefix(body["url"], "ftp://"))
Output
{
"_type": "log",
"body": {
"url": "https://api.example.com/v2/users",
"path": "report_2026_final.csv"
},
"resource": {...},
"attributes": {
"trimmed_url": "api.example.com/v2/users",
"no_match": "https://api.example.com/v2/users"
}
}
The https:// prefix was removed from the URL. When the prefix does not match (ftp://), the original string is returned unchanged.