From: Horacio Sanson Date: 2005-12-26T10:29:09+09:00 Subject: Re: Multibyte regexps... Thanks a lot... this seems to work ok. Where can I find documentation about this $KCODE global var and the "s" thing after each regexp? What does the s exactly mean? Do I have to put it only in regexps with japanese characters or any regexp? I tried both and saw no difference. When using Regexp.new to construct the regular expression how can I set the s to the end of it?? sorry for so many questions but I don't seem to find any docs about these options. Horacio Wednesday 21 December 2005 21:48、Yukihiro Matsumoto さんは書きました: > Hi, > > In message "Re: Multibyte regexps..." > > on Wed, 21 Dec 2005 18:59:59 +0900, Horacio Sanson writes: > |I am having some issues with regular expressions when working with > | japanese strings. > | > |Using ruby-1.8.3 on Windows XP home (Japanese version) I have this test: > | > |irb(main):271:0> s = "鞄" > |=> "\212\223" > |irb(main):272:0> l = "行" > |=> "\215s" > |irb(main):273:0> l =~ /s/ > |=> 1 > |irb(main):274:0> puts "#{$`}<<#{$&}>>#{$'}" > |E> > |=> nil > |irb(main):275:0> "#{$`}<<#{$&}>>#{$'}" > |=> "\215<>" > |irb(main):276:0> s =~ /l/ > |=> nil > > The encoding seems to be Shift_JIS. You have to specify encoding > before you make regular expression matching. Put s after every > regular expression. > > $KCODE="sjis" # to make p work right > p s = "鞄" > p l = "行" > p l =~ /s/s > puts "#{$`}<<#{$&}>>#{$'}" > p "#{$`}<<#{$&}>>#{$'}" > p s =~ /l/s > > matz.