Skip to content

Instantly share code, notes, and snippets.

@mzsanford
Created January 11, 2010 23:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mzsanford/274731 to your computer and use it in GitHub Desktop.
Save mzsanford/274731 to your computer and use it in GitHub Desktop.
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