Regex Get Last Part Of URL

Having trouble getting the last part of a URL using regex with all possible cases.

Currently my Regex: ([\w ]+)(?=[^/]*$)
Test url: http://www.token.com/post/another
Result: another

The problem is when the url is: http://www.token.com/post/another**/**
It won’t pull anything in this case b/c of the backslash “/”
Is there a way get the result “another” once again even when there’s a backslash?

1 Like

([^/]+)(?=/[^/]+/?$)

1 Like

How would you get it to result with both scenarios though:
http://www.token.com/post/answer
&
http://www.token.com/post/answer/

I want answer to be the result in both scenarios?

Got this to work: ([^/]+)(?=[^/]*/?$)

2 Likes

This topic was automatically closed after 70 days. New replies are no longer allowed.