Skip to content

Instantly share code, notes, and snippets.

@yazumoto
Created September 3, 2015 08:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yazumoto/96fa2a5731e674796118 to your computer and use it in GitHub Desktop.
Save yazumoto/96fa2a5731e674796118 to your computer and use it in GitHub Desktop.
Unicodeの文字(\u1234的なもの)を変換するRubyコード
str = '\u534a\u89d2\u82f1\u6570\u5b57'
str.gsub(/\\u([\da-fA-F]{4})/) { [$1].pack('H*').unpack('n*').pack('U*') } # => 半角英数字
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment