On Wed, Nov 19, 2008 at 10:55 AM, Jf Rejza <jfferriere / gmail.com> wrote:
> Hy,
>
> I would like to know how to extract a string delimited by too identical
> characters from an another string(of any length).
>
> ex string="rzerze@foo@rezrzgrtez" how to get (or match) the foo string

irb(main):016:0> string="rzerze@foo@rezrzgrtez"
=> "rzerze@foo@rezrzgrtez"
irb(main):017:0> (string.match /@(.*?)@/)[1]
=> "foo"

I don't quite understand the rest of your requirement. You mean delimited
by a string, i.e. the @ above is a variable, or by two of any character present
in a string? If it's the former:

irb(main):018:0> delimiter = "@"
=> "@"
irb(main):019:0> (string.match /#{delimiter}(.*?)#{delimiter}/)[1]
=> "foo"

if it's the latter, something like this might help:

irb(main):024:0> re = Regexp.new("([#{delimiter}])(.*)?\\1")
=> /([@abcde])(.*)?\1/
irb(main):025:0> string.match(re)[2]
=> "rze@foo@rezrzgrt"

It found the first 'e' as the delimiter, don't know why it took the
last 'e' as the other part of the delimiter, since I used a non-greedy
group for the middle part. Any ideas, someone?

Hope this helps,

Jesus.