How to get filename from a path string?

Sometimes you need to get an image name or document name from a string in your input data.
This is very easy with Alumio.

Answer

You can get just the filename (with extension) by using the “String: File basename” mapper.

Input:

{
  "path":"/ProductImages/image-thumb__14__api_product_image/Roundball-1252789.1.png"
}

Output:

{
  "path": "Roundball-1252789.1.png"
}

Extra solution

If you like to play on hard mode you can also use PCRE / REGEX to accomplish this.
Using the “String: PCRE replace” mapper like so:

This is done with “(^(.*[\/]))” as regular expression.
This regex captures everything before the last forward slash in a string.
Then the captured data is replaced with “$2” because $2 will always be null with this expression, thus essentially removing it.

The answer is in the topic