MatchData#[] などが返す String


#1

e$B$-$7$b$H$G$9e(B

MatchData e$B$Ne(B [] e$B$J$I$,JV$9e(B String e$B$K$D$$$F$J$N$G$9$,!e(B
chop! e$B$J$I$N$h$&$JI{:nMQ$N$$k%a%=%C%I$r8F$V$H!"%(%i!<$Ke(B
e$B$J$i$:JQ99$G$-$?$+$N$h$&$K8+$($FJQ99$5$l$F$J$$$G$9$,!e(B
freeze e$B$7$F!J$$k$$$Oe(B freeze e$B$5$l$?$+$N$h$&$J!K!e(B
e$BJQ99$7$h$&$H$7$?$i%(%i!<$K$J$k%%V%8%%/%H$K$9$k$+!e(B
e$B$$k$$$OI{:nMQ$K$h$kJQ99$,2DG=$J%
%V%8%%/%H$K$9$k$+!$Ne(B
e$B$I$A$i$+$N$[$&$,$$$$$N$G$O$J$$$G$7$g$&$+!)e(B


#2

e$B@.@%$G$9!#e(B

KISHIMOTO, Makoto wrote:

e$B$-$7$b$H$G$9e(B

MatchData e$B$Ne(B [] e$B$J$I$,JV$9e(B String e$B$K$D$$$F$J$N$G$9$,!e(B
chop! e$B$J$I$N$h$&$JI{:nMQ$N$$k%a%=%C%I$r8F$V$H!"%(%i!<$Ke(B
e$B$J$i$:JQ99$G$-$?$+$N$h$&$K8+$($FJQ99$5$l$F$J$$$G$9$,!e(B
freeze e$B$7$F!J$$k$$$Oe(B freeze e$B$5$l$?$+$N$h$&$J!K!e(B
e$BJQ99$7$h$&$H$7$?$i%(%i!<$K$J$k%%V%8%%/%H$K$9$k$+!e(B
e$B$$k$$$OI{:nMQ$K$h$kJQ99$,2DG=$J%
%V%8%%/%H$K$9$k$+!$Ne(B
e$B$I$A$i$+$N$[$&$,$$$$$N$G$O$J$$$G$7$g$&$+!)e(B

e$B$H$j$"$($:8=>u$K$D$$$F@bL@$7$^$9$H!"e(B
irb(main):001:0>m = abcde.match(/(.)b(.)d(.)/)
=> #<MatchData abcde 1:a 2:c 3:e>
irb(main):002:0> m1 = m[1]
=> a
irb(main):003:0> m1.chop!
=>
irb(main):004:0> m1
=>
irb(main):005:0> m[1]
=> a
e$B$H$$$&46$8$G!"e(B
e$B$D$^$je(B m[1] e$B$OCf$KJ]B8$7$F$$$ke(B String
e$B$N%3%T!<$rJV$7$F$$$k$N$G$9!#e(B

e$B<hF@85$Ne(B MatchedData e$B$N$3$H$r5$$K$;$:O.$j2s$;$k$N$G!e(B
e$B$3$l$O$3$l$G%a%j%C%H$,$$k$H;W$$$^$9$,!"e(B
e$B86K$rJV$7$?$[$&$,$$$$$H$$$&<gD%$K@Z$jBX$($^$9!)e(B


#3

NARUSE, Yui wrote:

e$B$"$k$$$OI{:nMQ$K$h$kJQ99$,2DG=$J%*%V%8%%/%H$K$9$k$+!"$Ne(B
=>
irb(main):005:0> m[1]
=> a
e$B$H$$$&46$8$G!"e(B
e$B$D$^$je(B m[1] e$B$OCf$KJ]B8$7$F$$$ke(B String e$B$N%3%T!<$rJV$7$F$$$k$N$G$9!#e(B

e$B<hF@85$Ne(B MatchedData e$B$N$3$H$r5$$K$;$:O.$j2s$;$k$N$G!e(B
e$B$3$l$O$3$l$G%a%j%C%H$,$$k$H;W$$$^$9$,!"e(B
e$B86K$rJV$7$?$[$&$,$$$$$H$$$&<gD%$K@Z$jBX$($^$9!)e(B

e$B$"!<!#e(B[] e$B$O%3%T!<$rJV$7$F$$$?$N$G$9$+!#e(B
e$B:#=q$$$F$$$k%3!<%I$G!"L@<(E*$Ke(B dup
e$B$7$F$?$N$G$9$,!"M>7W$@$C$?$o$1$G$9$M!#e(B

m = [abcde, a, c, e]
m1 = m[1]

e$B$H$7$?$H$-$H$NN`;w@-$+$i!"86K$rJV$7$?$[$&$,$$$$$h$&$J5$$b$7$^$9$,!e(B
e$B$=$&$9$k$H8=9T$N%3!<%I$X$N1F6A$,Bg$-$=$&$G$9$N$G!$3$NDs0F$O$R$C$3$a$^$9!#e(B