I don’t know what to add to my regular expression to make it only match the ‘exact’ patterns.
#users/(.+?)/# with this string users/john/someweirdstuff/ will be a match.
I am getting ‘john‘ and not ‘john/someweirdstuff‘ (which is a good step in the right direction), but I don’t want it to match at all. Because the string (which are supposed to be URLs) aren’t the same.
So basically, what do I add behind my reg exp to make it say “there should nothing after the last slash”
You should use the
$character that matches the end of the string.You should also avoid matching “any character (
.)” and you should match “any character which is not a slash ([^/]). As shown in the example).Also note I omitted the question mark (
?), the question mark in this instance changes the character matching from greedy (match as much as possible) to lazy (match as few as possible).Use it like so: