From: Robert Klemme Date: 2006-05-25T02:27:52+09:00 Subject: Re: RegExp Problem 2006/5/24, John W. Long : > John W. Long wrote: > > That makes perfect sense. So how do I get it to do what I want? > > I have something that works now: > > re = /(?:"[^"]*?"|'[^']*?')!/ > md = re.match %{ "this looks like "fun"!" } > md[0] #=> "\"fun\"!" > md = re.match %{ 'this looks like 'fun'!' } > md[0] => "'fun'!" > > Still, it makes me wonder if it's possible to do it with back references. I don't think you can have backreference in character class. In this case it's fairly easy. This is what I'd do re = %r{ (?: '[^']+' | "[^"]+" )! }xi Basically the same as what you did. But you do not need the reluctanct quantifiers because the negated char class prevents longer matches anyway. I'm not sure whether there is a performance difference. Kind regards robert -- Have a look: http://www.flickr.com/photos/fussel-foto/