Looking for a good way to do the following string manipulation in SQL Server (2008):
Given a string like the following (a URL):
/path/page.aspx?variable=value
I need to extract “page.aspx”. So the rule would be to grab the text between the last instance of a forward slash (“/”) and the first instance of a question mark (“?”).
It is important to note that there may be zero or more forward slashes and zero or more question marks in the string. So the following would be valid input:
/page.aspx?variable=value
page.aspx?variable=value
/path/page.aspx
page.aspx
This should handle all cases, including missing slashes or question marks: