Named capture and /g, /G option

In article [email protected],
“K.Kosako” [email protected] writes:

g, Ge$B%*%W%7%g%s$N$[$&$O!":#F|Cf$K<BAu$G$-$J$$$N$G!“e(B
e$B0l=54V8e$0$i$$$K$d$j$^$9!#e(B
e$B$=$N4V$K;EMM$K$D$$$F2?$+0U8+$,$”$kJ}$O$*4j$$$7$^$9!#e(B

e$B$=$m$=$m!"e(B/g, /Ge$B%%W%7%g%s$NDI2C$r<BAu$7$h$&$+$He(B
e$B9M$($F$$$^$9$,!"%
%W%7%g%sCM$NDj?tL>$O0J2<$Ne(B
e$BL>A0$GNI$$$G$7$g$&$+!)e(B

e$B$=$b$=$bI,MW$J$N$+$J$!!“$H$$$&5?Ld$,$d$C$Q$j$”$k$s$G$9$,!"$Ie(B
e$B$N$/$i$$;H$$$?$/$J$k$N$+e(B g, G e$B$r<BAu$9$kA0$K$7$P$i$/;H$C$F$e(B
e$B$k$
$k$H$$$&$N$O$I$&$G$7$g$&!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:28484] Re: named capture and /g, /G option”
on Wed, 29 Mar 2006 21:55:28 +0900, “K.Kosako” [email protected]
writes:
|
|K.Kosako wrote:
|> g, Ge$B%%W%7%g%s$N$[$&$O!“:#F|Cf$K<BAu$G$-$J$$$N$G!“e(B
|> e$B0l=54V8e$0$i$$$K$d$j$^$9!#e(B
|> e$B$=$N4V$K;EMM$K$D$$$F2?$+0U8+$,$”$kJ}$O$4j$$$7$^$9!#e(B
|
|e$B$=$m$=$m!"e(B/g, /Ge$B%
%W%7%g%s$NDI2C$r<BAu$7$h$&$+$He(B
|e$B9M$($F$$$^$9$,!”%
%W%7%g%sCM$NDj?tL>$O0J2<$Ne(B
|e$BL>A0$GNI$$$G$7$g$&$+!)e(B
|
|/g Regexp::DONT_CAPTURE_GROUP
|/G Regexp::CAPTURE_GROUP

e$B$$$$$s$8$c$J$$$G$7$g$&$+!#e(B

K.Kosako wrote:

g, Ge$B%*%W%7%g%s$N$[$&$O!":#F|Cf$K<BAu$G$-$J$$$N$G!“e(B
e$B0l=54V8e$0$i$$$K$d$j$^$9!#e(B
e$B$=$N4V$K;EMM$K$D$$$F2?$+0U8+$,$”$kJ}$O$*4j$$$7$^$9!#e(B

e$B$=$m$=$m!"e(B/g, /Ge$B%%W%7%g%s$NDI2C$r<BAu$7$h$&$+$He(B
e$B9M$($F$$$^$9$,!"%
%W%7%g%sCM$NDj?tL>$O0J2<$Ne(B
e$BL>A0$GNI$$$G$7$g$&$+!)e(B

/g Regexp::DONT_CAPTURE_GROUP
/G Regexp::CAPTURE_GROUP

e$B;29M$^$G$Ke(B/g, /Ge$B$N0UL#$O0J2<$NDL$j$G$9!#e(B

  1. /g, /Ge$B$N$I$A$i$b;XDj$7$F$$$J$$$H$-e(B(e$B%G%U%)%k%He(B)
    e$BL>A0$J$7%0%k!<%W$Ne(Bcapturee$B$O!"e(B
    e$BL>A0IU$-%0%k!<%W$,B8:_$9$k$+$I$&$+$K$h$C$F7h$^$ke(B
  2. /ge$B$r;XDje(B
    e$BL>A0$J$7%0%k!<%W$Oe(Bcapturee$B$7$J$$e(B
  3. /Ge$B$r;XDje(B
    e$BL>A0$J$7%0%k!<%W$Oe(Bcapturee$B$9$ke(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:28485] Re: named capture and /g, /G option”
on Thu, 30 Mar 2006 00:37:05 +0900, Tanaka A. [email protected]
writes:

|> e$B$=$m$=$m!“e(B/g, /Ge$B%%W%7%g%s$NDI2C$r<BAu$7$h$&$+$He(B
|> e$B9M$($F$$$^$9$,!"%
%W%7%g%sCM$NDj?tL>$O0J2<$Ne(B
|> e$BL>A0$GNI$$$G$7$g$&$+!)e(B
|
|e$B$=$b$=$bI,MW$J$N$+$J$!!”$H$$$&5?Ld$,$d$C$Q$j$“$k$s$G$9$,!”$Ie(B
|e$B$N$/$i$$;H$$$?$/$J$k$N$+e(B g, G e$B$r<BAu$9$kA0$K$7$P$i$/;H$C$F$e(B
|e$B$k$
$k$H$$$&$N$O$I$&$G$7$g$&!#e(B

e$B$=$&8@$o$l$k$HLB$C$F$7$^$$$^$9$M!#5#A3$H$7$J$$;d!#e(B
e$B$G$O!"%%W%7%g%sCM$ODI2C$9$k$,!"%%W%7%g%s$O8e2s$7$G$O$I$&$Ge(B
e$B$7$g$&!)e(B

Yukihiro M. wrote:

e$B$7$g$&!)e(B
e$BC/$+$,I,MW@-$r<($9$^$G!"2?$bF~$l$:$KJ]N1$H$7$F$$-$^$9!#e(B
e$B$=$N$H$-$K;d$,@8$-$F$$$kJ]>Z$b$J$$$N$G!"4{$K:n$C$Fe(B
e$B$7$^$C$?%Q%C%A$r0J2<$K<($7$F$
$-$^$9!#e(B

e$B>.Gwe(B

— /home/kosako/ruby_lang_org/ruby/re.c 2006-03-26 21:52:36.427444000
+0900
+++ re.c 2006-03-29 22:45:34.554899200 +0900
@@ -159,8 +159,8 @@ rb_memsearch(char *x0, long m, char *y0,
#define KCODE_FIXED FL_USER4
#define KCODE_MASK (KCODE_EUC|KCODE_SJIS|KCODE_UTF8)

-#define ARG_REG_OPTION_MASK 0x0f
-#define ARG_KCODE_UNIT 16
+#define ARG_REG_OPTION_MASK ((ONIG_OPTION_CAPTURE_GROUP<<1) - 1)
+#define ARG_KCODE_UNIT (ONIG_OPTION_CAPTURE_GROUP<<1)
#define ARG_KCODE_NONE (ARG_KCODE_UNIT * 1)
#define ARG_KCODE_EUC (ARG_KCODE_UNIT * 2)
#define ARG_KCODE_SJIS (ARG_KCODE_UNIT * 3)
@@ -185,6 +185,12 @@ static int char_to_option(int c)
case ‘m’:
val = ONIG_OPTION_MULTILINE;
break;

  • case ‘g’:

  •  val = ONIG_OPTION_DONT_CAPTURE_GROUP;
    
  •  break;
    
  • case ‘G’:

  •  val = ONIG_OPTION_CAPTURE_GROUP;
    
  •  break;
    

    default:
    val = 0;
    break;
    @@ -417,6 +423,10 @@ rb_reg_desc(const char *s, long len, VAL
    rb_str_buf_cat2(str, “i”);
    if (RREGEXP(re)->ptr->options & ONIG_OPTION_EXTEND)
    rb_str_buf_cat2(str, “x”);

  • if (RREGEXP(re)->ptr->options & ONIG_OPTION_DONT_CAPTURE_GROUP)

  •   rb_str_buf_cat2(str, "g");
    
  • if (RREGEXP(re)->ptr->options & ONIG_OPTION_CAPTURE_GROUP)

  •   rb_str_buf_cat2(str, "G");
    

    if (FL_TEST(re, KCODE_FIXED)) {
    switch ((RBASIC(re)->flags & KCODE_MASK)) {
    @@ -631,11 +641,13 @@ rb_reg_casefold_p(VALUE re)

    • Regexp::IGNORECASE                  #=> 1
      
    • Regexp::EXTENDED                    #=> 2
      
    • Regexp::MULTILINE                   #=> 4
      
    • Regexp::DONT_CAPTURE_GROUP          #=> 128
      
    • Regexp::CAPTURE_GROUP               #=> 256
      
    • /cat/.options                       #=> 128
      
    • /cat/ix.options                     #=> 131
      
    • Regexp.new('cat', true).options     #=> 129
      
    • Regexp.new('cat', 0, 's').options   #=> 384
      
    • /cat/.options                       #=> 64
      
    • /cat/ix.options                     #=> 67
      
    • Regexp.new('cat', true).options     #=> 65
      
    • Regexp.new('cat', 0, 's').options   #=> 48
      
    • r = /cat/ix
      
    • Regexp.new(r.source, r.options)     #=> /cat/ix
      

@@ -2346,6 +2358,8 @@ Init_Regexp(void)
rb_define_const(rb_cRegexp, “IGNORECASE”,
INT2FIX(ONIG_OPTION_IGNORECASE));
rb_define_const(rb_cRegexp, “EXTENDED”,
INT2FIX(ONIG_OPTION_EXTEND));
rb_define_const(rb_cRegexp, “MULTILINE”,
INT2FIX(ONIG_OPTION_MULTILINE));

  • rb_define_const(rb_cRegexp, “DONT_CAPTURE_GROUP”,
    INT2FIX(ONIG_OPTION_DONT_CAPTURE_GROUP));

  • rb_define_const(rb_cRegexp, “CAPTURE_GROUP”,
    INT2FIX(ONIG_OPTION_CAPTURE_GROUP));

    rb_global_variable(&reg_cache);

e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B

In message “[ruby-dev:28487] Re: named capture and /g, /G option”
on Mar.30,2006 02:25:13, [email protected] wrote:
| |> e$B$=$m$=$m!“e(B/g, /Ge$B%%W%7%g%s$NDI2C$r<BAu$7$h$&$+$He(B
| |> e$B9M$($F$$$^$9$,!"%
%W%7%g%sCM$NDj?tL>$O0J2<$Ne(B
| |> e$BL>A0$GNI$$$G$7$g$&$+!)e(B
| |
| |e$B$=$b$=$bI,MW$J$N$+$J$!!”$H$$$&5?Ld$,$d$C$Q$j$“$k$s$G$9$,!”$Ie(B
| |e$B$N$/$i$$;H$$$?$/$J$k$N$+e(B g, G e$B$r<BAu$9$kA0$K$7$P$i$/;H$C$F$e(B
| |e$B$k$
$k$H$$$&$N$O$I$&$G$7$g$&!#e(B
|
| e$B$=$&8@$o$l$k$HLB$C$F$7$^$$$^$9$M!#5#A3$H$7$J$$;d!#e(B
| e$B$G$O!"%%W%7%g%sCM$ODI2C$9$k$,!"%%W%7%g%s$O8e2s$7$G$O$I$&$Ge(B
| e$B$7$g$&!)e(B

e$B=PCY$l$^$7$?$,!“$=$b$=$be(B g, G e$B$NM-L5$G2?$,$I$&$J$k$N$+L@3N$Ge(B
e$B$J$$$h$&$J5$$,$7$^$9$N$G!”$b$&$A$g$C$H@bL@$,M_$7$$$N$G$9$,!"e(B
e$B$I$&$G$7$g$&$+!#e(B

[ruby-dev:28453]e$B$G$Oe(B4e$B$D$N%1!<%9$K$D$$$F@bL@$,$5$l$F$$$k$o$1$Ge(B
e$B$9$,!“$3$l$G$O@bL@$,O3$l$F$$$k$h$&$K;W$$$^$9!#e(B
e$B0J2<$NM}2r$,@5$7$$$+$I$&$+!”$^$?!"5?LdE@$NItJ,$O$I$&$J$k$N$+!"e(B
e$B$r@bL@$7$F$$$?$@$1$k$H!"e(Bg, G
e$B$NI,MW@-$K$D$$$F$b$&$A$g$C$H9M$(e(B
e$B$k$3$H$,$G$-$k$h$&$K;W$$$^$9!#e(B

(1) e$B%%W%7%g%s$J$7!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J!”$H$$$&46$8$G$9$,!“L>A0$D$-Ja3M<0=89g$re(B
e$B4^$`$+$I$&$+$Ge(B()e$B$N07$$$,JQ2=$9$k$N$,$I$&$7$F$b5$$K$J$C$F$7$^e(B
e$B$$$^$9!#e(B
e$B0U?^$O$o$+$k$N$G!”$7$c!<$J$$$+$J!<$H$b;W$$$^$9$,e(B…

e$B5$$K$J$k$N$O0l4S@-$G$7$g$&$+e(B?

e$B$b$7$=$&$G$“$l$P!”$=$NE@$O$O;H$$0W$5$rDI5a$7$F0l4S@-$r6J$2$?e(B
e$B;EMM$J$N$G!“5$$K$J$k$N$O$o$+$j$^$9!#$G$b!”;H$$0W$5$N$[$&$,=Ee(B
e$BMW$@$H;W$C$F$$$^$9!#e(B

e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B

In message “[ruby-dev:28493] Re: named capture and /g, /G option”
on Mar.30,2006 21:11:04, [email protected] wrote:
| e$B5$$K$J$k$N$O0l4S@-$G$7$g$&$+e(B?
|
| e$B$b$7$=$&$G$“$l$P!”$=$NE@$O$O;H$$0W$5$rDI5a$7$F0l4S@-$r6J$2$?e(B
| e$B;EMM$J$N$G!“5$$K$J$k$N$O$o$+$j$^$9!#$G$b!”;H$$0W$5$N$[$&$,=Ee(B
| e$BMW$@$H;W$C$F$$$^$9!#e(B

e$B0l4S@-$N$[$&$G$9!#$J$N$G!"G<F@$O$7$F$^$9!#e(B

e$B;H$$$d$9$5$X$N1F6A$O!“$J$K$+;W$$$b$h$i$J$$$3$H$,$”$k$s$8$c$Je(B
e$B$$$+$H$$$&5$$O$9$k$N$G$9$,!"<B:]$KLdBj$,5/$-$=$&$J;vNc$O;W$$e(B
e$B$D$$$F$$$^$;$s!#e(B
lib/urie$B$_$?$$$J@55,I=8=$r$/$C$D$1$^$/$k%?%$%W$N%3!<%I$rCfESH>e(B
e$BC<$K?($C$?$j$7$?$i;$K$=$&$J5$$,$7$?$j$7$?$N$G$9$,!"JL$K:#2se(B e$B$NJQ99$,$"$C$F$b$J$/$F$bCfESH>C<$K?($C$?$i$d$C$Q$j;$K$=$&$Ge(B
e$B$9$7e(B :slight_smile:

e$B$=$l$G$O!#e(B