From: Alan Chen Date: 2002-11-15T02:49:58+09:00 Subject: Re: regex help On Thu, Nov 14, 2002 at 03:39:09PM +0900, Shashank Date wrote: > Using ruby 1.7.3 (2002-10-12) [i386-mswin32] on Win XP (Home) > > Trying to creat a regex which will match a single-quoted string. > My first attempt 'almost' works: /\'.*?\'/ > > But then I also want it to match single-quoted strings which have embedded > single quotes. > To embed, you can escape a single quote by putting another single quote just > before it. > For example : > > m = /\'.*?\'/.match(%Q{This is a 'single ''quoted'' string' with only one > match}) > puts m[0] # ^ ^ > # These are two single quotes and not a > double quote > > > I want this to print: 'single ''quoted'' string' . > But I am getting: 'single ' Since this type of regex question comes up regularly, I wonder how difficult it would be to provide a regex extension which matches pairs of quoted characters; either identical chars like ' or " or character pairs () or {}, etc... -- Alan Chen Digikata LLC http://digikata.com