Sounds like by “the last part”, you mean “the part before the query string or after the last slash if there’s no query string”, right?
Well, you can find the bit after the last slash with this: /([^\/]+)$/
And you can find the bit between a slash and the first question mark like this: /([^\/]+)\?/
.
Neither of those will work for example D, though, as it has another slash before the query string. For that example, you’d need something like this: /([^\/]+)\/\?/
So if we combine all those, we get something like this: /([^\/]+)(?:\/?\?|$)/
As for converting to camel case, you’ll have to do that separately, and there’s no regex that can capitalize for you; you’ll need to use a regex to capture all hyphen-letter combos one by one and replace them with the matched letter .toUpperCase
.
EDIT Just realized the regex I gave you won’t match B. So you need another case for a slash at the end, which makes the final regex this: /([^\/]+)\/?(?:\?|$)/
. This says “match a string of non-slashes followed by possibly a slash, then definitely followed by either a question mark or the end of the string”.
3
solved What is the RegEx to just return the last part of the URL [closed]