Skip to content

Instantly share code, notes, and snippets.

@mzsanford
Created January 11, 2010 23:52
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 mzsanford/274737 to your computer and use it in GitHub Desktop.
Save mzsanford/274737 to your computer and use it in GitHub Desktop.
latin = "6"
egypt = [0x0666].pack('U') # Arabic-Indic 6 - ٦
china = [0x516d].pack('U') # 六
braille = [0x2820].pack('U')
chars = [latin, egypt, china, braille ]
patterns = [ /\d/, /[[:digit:]]/, /[[:alnum:]]/]
chars.each do |char|
puts " #{char}.to_i = #{char.to_i}"
end
patterns.each do |pattern|
puts " Pattern: #{pattern}"
chars.each do |char|
puts " #{char}: #{!!char.match(pattern)}"
end
end
# Output:
#
# 6.to_i = 6
# ٦.to_i = 0
# 六.to_i = 0
# ⠠.to_i = 0
# Pattern: (?-mix:\d)
# 6: true
# ٦: false
# 六: false
# ⠠: false
# Pattern: (?-mix:[[:digit:]])
# 6: true
# ٦: false
# 六: false
# ⠠: false
# Pattern: (?-mix:[[:alnum:]])
# 6: true
# ٦: false
# 六: false
# ⠠: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment