I have stumbled upon a regular expression trap - so called greedy (or ungreedy) trap. In short, in regex the ungreedy operator does not mean the shortest possible match.
I explain here the problem description where I have faced it and workaround I came to use.