Looker Studio calculated field – File name from URL
March 25, 2022
- by Mehdi Oudjida
The Looker Studio calculated field below returns the file name with the related extension from a field providing an absolute URL.
- Explanations of the regular expression applied as the second parameter for the substring extraction
- “\w” means word characters (digits, letters and underscore characters)
- “\.” for dot character
- “-” for hyphen character
- “$” for the instruction corresponding to the end of the string
- Input
- Any file URL. With or without the related protocol. With or without the hostname
- Examples
- https://www.mysite.com/myfolder/mysubfolder/my-file.pdf
- www.mysite.com/myfolder/mysubfolder/my-file.pdf
- /myfolder/mysubfolder/my-file.pdf
- Output
- The file name
- Example
- my-file.pdf
- Used functions
URL file name
REGEXP_EXTRACT(My url field, '/([\\w\\.-]+)$')