Regex To Match Strings After The Last Slash In A String

Category: URI

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:

Rate This Regex
Sending
User Review
0 (0 votes)

Expression Flags

Flags Description
i Ignore case sensitive.
g Allows global search.
m Allows multiline search.