From: why the lucky stiff Date: 2002-11-15T00:43:44+09:00 Subject: Re: regex help Shashank Date (sdate@kc.rr.com) wrote: > Now I would like to modify it to generate the following: > > "Here I have 'two ''quoted'' matches' and 'here''s the second' one.".scan( > ???) > ==> [["Here"],["I"],["have"],["two ''quoted'' matches"], ["and"],["here''s > the second"],["one."]] A simpler regexp to gather characters around the quoted string: quote1_re = /((?:''|[^'])+)/ str = "Here I have 'two ''quoted'' matches' and 'here''s the second'." str.scan( quote1_re ) ==>[["Here I have "], ["two ''quoted'' matches"], [" and "], ["here''s the second"], ["."]] For the outcome you'd like: quote1_re = /(?:'((?:''|[^'])+)'|(\S+))/ str.scan( quote1_re ).flatten.compact ==>["Here", "I", "have", "two ''quoted'' matches", "and", "here''s the second", "."] Definitely a lot slower. You could probably reduce it further, but it's enough to get you started. Goo luck. _why