I’m looking specifically for a regular expression that will grab the last term of a URL. This is not always a file name, it may not end in .html or .php, so I’ll need to make sure that the regular expression is grabbing the last term from the URL.
Example:
I need to grab http://www.mydomain.com/anything_can_be_here/thankyoupage
I need to extract “thankyoupage” even when there can be any term preceding it in the URL.
Also note, there is no file extension on the thankyoupage URL segment.
This should do it:
For example, the result of this:
is this array:
And this:
Results in:
And this:
Results in
null.And your component is in
m[1]and that comes from([^\/]+). The(?:[^\/]+)will take care of the hostname (and the userinfo if it happens to be present), the(?:\?.*)?$part will take care of any trailing CGI arguments.Depending on your URLs, you could replace
^(?:http:\/\/)?with^http:\/\/.