Create a gist now

Instantly share code, notes, and snippets.

latin = "a"
arabic = [0xfeb6].pack('U') # Sheen, ش
cjk = [0x3333].pack('U') # HUIITO, ㌳
kcodes = [ 'NONE', 'u', 's' ]
chars = [latin, arabic, cjk]
patterns = [ /\w/, /\W/, /[[:punct:]]/ ]
kcodes.each do |kcode|
$KCODE = kcode
puts "KCODE = #{kcode}"
patterns.each do |pattern|
puts " Pattern: #{pattern}"
chars.each do |char|
puts " #{char}: #{!!char.match(pattern)}"
end
end
end
# Output:
#
#KCODE = NONE
# Pattern: (?-mix:\w)
# a: true
# ﺶ: false
# ㌳: false
# Pattern: (?-mix:\W)
# a: false
# ﺶ: true
# ㌳: true
# Pattern: (?-mix:[[:punct:]])
# a: false
# ﺶ: false
# ㌳: false
#KCODE = u
# Pattern: (?-mix:\w)
# a: true
# ﺶ: true
# ㌳: true
# Pattern: (?-mix:\W)
# a: false
# ﺶ: false
# ㌳: false
# Pattern: (?-mix:[[:punct:]])
# a: false
# ﺶ: false
# ㌳: false
#KCODE = s
# Pattern: (?-mix:\w)
# a: true
# ﺶ: true
# ㌳: true
# Pattern: (?-mix:\W)
# a: false
# ﺶ: true
# ㌳: true
# Pattern: (?-mix:[[:punct:]])
# a: false
# ﺶ: false
# ㌳: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment