From: "s.ross" Date: 2008-04-07T10:59:41+09:00 Subject: Re: Regex and non-greedy matching? Hi-- On Apr 6, 2008, at 4:25 PM, Marc Heiler wrote: > 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]+)>(.+?)<\/>/ > > $1 # => "b" > $2 # => "name: > > $2 should only be name: > and $1 should only be lightblue You might want to look into hpricot (http://code.whytheluckystiff.net/hpricot/ ). It will give you pretty reliable parsing of XML markup. What you have here is not valid XML because the closing tag for is not but on the chance that it's a typo, I really recommend giving hpricot a try.