# "$B$"$$$&(B"\[/.\].encoding #=\> ASCII-8BIT $B$H(B /hoge/.to\_s.encoding

**URL:** <https://www.ruby-forum.com/t/b-b-encoding-ascii-8bit-b-h-b-hoge-to-s-encoding/117295>\
**Category:** Development\
**Created:** [October 15, 2007, 7:35pm UTC](https://www.ruby-forum.com/t/b-b-encoding-ascii-8bit-b-h-b-hoge-to-s-encoding/117295 "2007-10-15T19:35:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NARUSES\_Yui](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/258eb7/32.png) [@NARUSES\_Yui](https://www.ruby-forum.com/u/NARUSES_Yui)\
**Post date:** [October 15, 2007, 7:35pm UTC](https://www.ruby-forum.com/t/b-b-encoding-ascii-8bit-b-h-b-hoge-to-s-encoding/117295/1 "2007-10-15T19:35:52Z")

</div>

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

# -_- coding: UTF-8 -_-

str = “e$B$”$$$&$($\*e(B"  
m = str[/./]  
p m.encoding #=\> Encoding:ASCII-8BIT

e$B$H$J$k$N$G$9$,!"$3$3$Oe(B UTF-8  
e$BJ8;zNs$rJV$9$Y$-$G$O$J$$$G$7$g$&$+!#$?$V$se(B  
e$BC1$Ke(B rb\_str\_new4() e$B$J$@$1$C$]$$$G$9$,!#e(B

# Index: string.c

— string.c (e$B%j%S%8%g%se(B 13711)  
+++ string.c (e$B:n6H%3%T!\<e(B)  
@@ -307,6 +307,7 @@  
}  
else if (STR\_ASSOC\_P(orig) || STR\_EMBED\_P(orig)) {  
str = str\_new(klass, RSTRING\_PTR(orig), RSTRING\_LEN(orig));

- 

```
  rb_enc_copy(str, orig);

```

}  
else {  
str = str\_new4(klass, orig);

e$B$^$?!“e(B  
ru = Regexp.new(”\xE3\x81\x82".force\_encoding(‘UTF-8’))  
ru.encoding #=\> Encoding:UTF-8  
p ru.to\_s.encoding # =\> Encoding:ASCII-8BIT  
re = Regexp.new("\x82\xA0".force\_encoding(‘EUC-JP’))  
re.encoding #=\> Encoding:EUC-JP  
rr = Regexp.union(ru,re) #=\> /(?-mix:\343\201\202)|(?-mix:\202\240)/  
rr.encoding #=\> Encoding:ASCII-8BIT  
e$B$H$J$k$N$G$9$,!"$3$l$O0U?^$7$?F0:n$G$7$g$&$+e(B
