It could happen you have a string and would like to replace everything except what you select with the PCRE / REGEX.
For example we have the string:
“/ProductImages/image-thumb__14__api_product_image/Roundball-1252789.1.png”
And would like to remove everything except “Roundball-1252789.1.png”.
Answer
Your first thought might be to use the “String: PCRE replace” mapper with the following regex to select just the content behind the last forward slash: “([^/]+$)”.
This will however not work with the “String: PCRE replace” mapper as that content is not what we are trying to replace.
To fix this you need to invert the regex, in this case: “(^(.*[\/]))” to select everything up until the last forward slash.
And then use the “String: PCRE replace” mapper to replace it with an empty value (null).
This can be done by replacing it with “$2”, because with this regular expression $2 will always be null.
The input:
{
"path":"/ProductImages/image-thumb__14__api_product_image/Roundball-1252789.1.png"
}
The output:
{
"path": "Roundball-1252789.1.png"
}
This specific use case can however be solved much easier!