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:
Result: another

The problem is when the url is:**/**
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:

I want answer to be the result in both scenarios?

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


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