I am using C# to parse XML, and this happens to me. This is not exactly what I am doing, but the same idea. Single line option is turned on.
So if I have a string:
Start xxx A xxx Pattern xxx End
Start xxx B xxx Pattern xxx End
Start xxx C xxx Pattern xxx End
if I want to extract "Start xxx B xxx Pattern xxx End", I use
(Start.*?B.*?Pattern.*?End)
But this thing really matches:
Start xxx A xxx Pattern xxx End
Start xxx B xxx Pattern xxx End
So I said, ok, maybe I should use:
.*(Start.*?B.*?Pattern.*?End)
This does extract what I want, but if I have
Start xxx A xxx Pattern xxx End
....
Start xxx B xxx Pattern xxx End
Start xxx C xxx Pattern xxx End
I will match everything below,
Start xxx A xxx Pattern xxx End
....
Start xxx B xxx Pattern xxx End
and then extract what I want. And I think this huge match makes my program slow for some reason.
So is there a way for me to specify that I want the shortest match of all, just matching
Start xxx B xxx Pattern xxx End
P.S. "xxx" in string does not quite have any pattern.
I believe it is some greedy, non-greedy issue, can anyone help?