Since it was briefly touched among my colleagues today, let me share our insights. The question was if a regular expression like (/.*somepath$) would match a path starting with a “/” and ending with “somepath”, or if it would be matching anything after “/”. As we found out, the RegEx is right, it matches paths like /path/to/somepath or simply /somepath.
There is a related question leading us to to the question of laziness. What if we have an expression like str.*g
And what if it is followed by ? so that we have
str.*?g
Here’s an example: looking for mou.*
the search starts at the first occurence of mouseX, ending at the end of the line (the dot doesn’t match newline). This is a greedy capture.
But if we are using the expression
mou.*?
we can see that the capture stops right after the first occurence of mou. It’s taking the shortest match: this is a lazy capture.