Regex ungreedy from the left side (i.e., narrowest match possible from both sides)

m1lkym1ke

New Member
Let's say I'm trying to match \[code\]/dog.*lab/\[/code\] against this text:"I have a dog. My dog is a black lab. He was created in a laboratory."Greedily, it would match "dog. My dog is a black lab. He was created in a lab".I want to find the matches that are narrowest from both sides. If I use the ungreedy modifier like
\[code\]/dog.*?lab/\[/code\] or \[code\]/dog.*lab/U\[/code\] it will match less but still too much:
"dog. My dog is a black lab"Is there a way to make my search ungreedy from the left also, thus matching only "dog is a black lab"?Much thanks. Sorry for the contrived example.
 
Back
Top