Austin,

> I'm doing something that required RLE, and the code
> that I translated from Perl to do this included the
> following regexp:
>
>   /^(.*?)((.)\2{2,127})(.*?)$/ois
>     # Later code using $1 (.*?), $2 (...), $3 (.*?)
> ...
> Thus, the translated version is:
>
>   /^(.*?)((.)\3{2,127})(.*?)$/m
>
> While what's happening makes sense, I'm wondering if
> it's correct -- how deep should backreferences be
> nested and considered part of the process?

    Your basic problem is that the original regular expression did not work
in Perl.  Perl and Ruby both count backreferences as the order of the left
parenthesis of the expression (i.e. the first left parenthesis defines $1,
the second defines $2, etc.).  Therefore the original regular expression
would have never matched, since the backreference \2 was yet fully defined
where it appeared (i.e. it tried to define some sort of recursive
backreference):

%perl -e '"xyyyyyyyz" =~ /^(.*?)((.)\2{2,127})(.*?)$/; print
"($1,$2,$3,$4)\n";'
(,,,)

    Changing the backreference to \3 fixes it in Perl:

%perl -e '"xyyyyyyyz" =~ /^(.*?)((.)\3{2,127})(.*?)$/; print
"($1,$2,$3,$4)\n";'
(x,yyyyyyy,y,z)

    ... as well as in Ruby:

%ruby -e '"xyyyyyyyz" =~ /^(.*?)((.)\3{2,127})(.*?)$/; print
"(#{$1},#{$2},#{$3},#{$4})\n";'
(x,yyyyyyy,y,z)

    By the way, to match the original options ('ois') you would want 'oim'
in Ruby.  Since there are no embedded variables in the regular expression,
the 'o' option is meaningless.  However, the 'i' option is ignore case,
which would seem to be a bad idea for RLE.  My guess is that it is a
mistake.

    I hope this helps!

    - Warren Brown