I am using PCRE|^/foo/(.*?)(?::(?:bar)?)?$| or |^/foo/(.*?)(?::bar)?:?$| this will be a replace so we want to strip : and :bar from the end while doing the replacement. I know the two are not exactly the same but it does not matter much here.
I am using PCRE |^/foo/(.*?)(?::(?:bar)?)?$| or |^/foo/(.*?)(?::bar)?:?$| this will be a replace so we
Share
I would use the first one as it only has to check for
:once. The second one could match the first three characters of:batbefore having to backtrack, then check for:again. Also, the second one could match:bar:whereas the first one can’t. The actual speed difference would be tiny. The second way would be better written as/^\/foo\/(.*?)(?::bar|:)?$/Try not to use regex metacharacters as delimiters!