From: "Jesús Gabriel y Galán" Date: 2008-11-19T20:28:18+09:00 Subject: Re: RegExp problem On Wed, Nov 19, 2008 at 11:58 AM, Florian Gilcher wrote: > Actually the correct regexp is: > > delimiter = Regexp.escape(delimiter) > /#{delimiter}[^#{delimiter}]*#{delimiter}/ > > Read: The delimiter - an unspecified number of non-delimiter-characters - > the delimiter. > > Otherwise, you too heavily rely on the behaviour of the library, when it > coms to the dot. Hi Florian, I don't get what you mean by "too heavily rely", I mean, you are always relying on the behaviour of the regexp library when it comes to everything, so if you know how the dot, the * and the ? work in Ruby why is your regexp better than the proposed one? Anyway I have realized I had a mistake in my regexp (I had the ? outside of the group, and not next to the *). So fixing that: irb(main):034:0> string="rzerze@foo@rezrzgrtez" => "rzerze@foo@rezrzgrtez" irb(main):035:0> re = Regexp.new("([#{delimiter}])(.*?)\\1") => /([abcde])(.*?)\1/ irb(main):036:0> string.match(re)[2] => "rz" Now works as I intended. With your version: irb(main):037:0> re = /([#{delimiter}])([^#{delimiter}]*)\1/ => /([abcde])([^abcde]*)\1/ irb(main):038:0> string.match(re)[2] => "rz" works too. So I would like to know why would be one preferred over the other. Jesus.