3
"d̪".chars.to_a

私にくれます

["d"," ̪"]

Rubyに書記素で分割させるにはどうすればよいですか?

["d̪"]
4

4 に答える 4

1

http://www.yoshidam.net/unicode.txtに記載されているunicode.gemUnicode::text_elementsから使用します。

irb(main):001:0> require 'unicode'
=> true
irb(main):006:0> s = "abčd̪é"
=> "abčd̪é"
irb(main):007:0> s.chars.to_a
=> ["a", "b", "č", "d", "̪", "é"]
irb(main):009:0> Unicode.nfc(s).chars.to_a
=> ["a", "b", "č", "d", "̪", "é"]
irb(main):010:0> Unicode.nfd(s).chars.to_a
=> ["a", "b", "c", "̌", "d", "̪", "e", "́"]
irb(main):017:0> Unicode.text_elements(s)
=> ["a", "b", "č", "d̪", "é"]
于 2012-10-22T20:10:46.710 に答える
-1

Ruby2.0

   str = "d̪"

   char = str[/\p{M}/]

   other = str[/\w/]
于 2013-08-09T08:09:56.717 に答える