Google Data Studio calculated field – File name from URL


The Google Data Studio calculated field below returns the file name with the related extension from a field providing an absolute URL.


URL file name
REGEXP_EXTRACT(My url field, '/([\\w\\.-]+)$')
  • 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


  • Explanations of the regular expression applied as the 2 parameter for string 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
Share