From: ts Date: 2001-05-15T23:02:40+09:00 Subject: [ruby-talk:15162] Regexp (a\1) Someone can explain me this result : pigeon% ruby -e '/(a\1)/ =~ "a\001"; p $&' "a" pigeon% With this comment, I expect a match on "a\001" /* Can't back reference to a subexpression if inside of it. */ pigeon% diff -u regex.c~ regex.c --- regex.c~ Sat Feb 10 18:33:35 2001 +++ regex.c Tue May 15 15:48:34 2001 @@ -2248,6 +2248,7 @@ if (!ISDIGIT(c)) PATUNFETCH; if (c1 >= regnum) { + need_to_get_octal: /* need to get octal */ p = p_save; c = scan_oct(p_save, 3, &numlen) & 0xff; @@ -2259,9 +2260,24 @@ } /* Can't back reference to a subexpression if inside of it. */ - for (stackt = stackp - 2; stackt > stackb; stackt -= 5) - if (*stackt == c1) - goto normal_char; + for (stackt = stackp - 2; stackt > stackb; ) { + switch (*stackt) { + case '(': + if (stackt[-2] == c1) + goto need_to_get_octal; + stackt -= 5; + break; + case '!': + stackt--; + case '=': + case '>': + stackt -= 4; + break; + default: + stackt -= 3; + break; + } + } laststart = b; BUFPUSH(duplicate); BUFPUSH(c1); pigeon% pigeon% ./ruby -e '/(a\1)/ =~ "a\001"; p $&' "a\001" pigeon% Guy Decoux