Assuming I have this regular expression: '#artists/(.*)/#' and I want to match this string: '/artists/alesana/wires-and-the-concept-of-breathing/' how can I make sure that it only matches 'alesana' and not 'alesana/wires-and-the-concept-of-breathing'.
So in other words, how can I let my reg exp cohere to the slashes.
Technically I am gonna make another routing rule for artists/(.*)/(.*) but I know I’m gonna run in this problem somewhere else sooner or later.
Make the regular expression non-greedy with the
?character. This will essentially find the shortest match possible:Read more: Lazy quantification in regular expressions