Skip to content

Instantly share code, notes, and snippets.

@brixen
Created December 15, 2012 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brixen/4290155 to your computer and use it in GitHub Desktop.
Save brixen/4290155 to your computer and use it in GitHub Desktop.
# encoding: utf-8
re = /[\u{20}-\u{7E}]/
p re, re.encoding, re.source, re.source.encoding
re_s = "\u{20}-\u{7E}"
p re_s, re_s.encoding
re = /[#{re_s}]/
p re, re.encoding, re.source, re.source.encoding
$ ruby1.9.3 -v regexp.rb
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin10.8.0]
/[\u{20}-\u{7E}]/
#<Encoding:US-ASCII>
"[\\u{20}-\\u{7E}]"
#<Encoding:US-ASCII>
" -~"
#<Encoding:UTF-8>
/[ -~]/
#<Encoding:US-ASCII>
"[ -~]"
#<Encoding:US-ASCII>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment