From: Nobuyoshi Nakada Date: 2008-04-07T10:05:12+09:00 Subject: Re: Regex and non-greedy matching? Hi, At Mon, 7 Apr 2008 08:25:28 +0900, Marc Heiler wrote in [ruby-talk:297262]: > I have a slight problem. I have strings with some tags such as > > 'name:' > > I need to match "name:" and "lightblue" > In other words: > - What is between <> > and > - What is inside the first <> right next to "name:" > > The following regex does not work: > > 'name:' =~ /<([a-zA-Z]+)>(.+?)<\/>/ /<([a-zA-Z]+)>.*?([^<>]+)<\/>/ =~ "name:" > $2 should only be name: > and $1 should only be lightblue Non-greedy matching doesn't mean the shortest result matching. It matches at the leftmost position. -- Nobu Nakada