From: "John W. Long" Date: 2006-05-25T00:13:41+09:00 Subject: RegExp Problem Hi, I'm having a little trouble getting Ruby to match quotes correctly. Suppose I wanted to extract any quoted string followed by an exclamation point. I'd like my regular expression match either single or double quotes. I thought the following might work: re = /(['"])([^\1]*?)\1!/ md = re.match %{ "this looks like "fun"!" } md[0] #=> "\"this looks like \"fun\"!" But as you can see instead of matching <"fun"!> it matched <"this looks like "fun"!>, despite the fact that I've told it to match anything but the character that was used to quote it: [^\1]*? It works beautifully if I tell it to match either single quotes or double quotes, but I can't write it to match either in a single regular expression: re = /"([^"]*?)"!/ md = re.match %{ "this looks like "fun"!" } md[0] #=> "\"fun\"!" Or: re = /'([^']*?)'!/ md = re.match %{ 'this looks like 'fun'!' } md[0] #=> "'fun'!" Why does the first regex not do what I want? -- John Long http://wiseheartdesign.com http://radiantcms.org