Regex To Match Strings After The Last Slash In A String

A regular expression that matches everything after the last slash in a string (like a URL or a file/folder path).

Can be useful in finding out file names or query strings in a URL.

/[^/]+$/g

Matches:

  • https://regexpattern.com/index.html
  • https://regexpattern.com/index.html?key=value
  • /path/to/regex

Non-matches:

  • https://regexpattern.com/index.html/
  • /path/to/regex/

See Also:

Regex Is Copied!