[javascript] regex pattern to match the end of a string

Can someone tell me the regex pattern to match everything to the right of the last "/" in a string.

For example, str="red/white/blue";

I'd like to match "blue" because it is everything to the right of the last "/".

Many thanks!

This question is related to javascript regex

The answer is


Use this Regex pattern: /([^/]*)$


Use following pattern:

/([^/]+)$

Should be

~/([^/]*)$~

Means: Match a / and then everything, that is not a / ([^/]*) until the end ($, "end"-anchor).

I use the ~ as delimiter, because now I don't need to escape the forward-slash /.


Something like this should work: /([^/]*)$

What language are you using? End-of-string regex signifiers can vary in different languages.