Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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