Created
March 5, 2011 17:06
-
-
Save raws/856509 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby -vKU nick_matching.rb | |
ruby 1.8.7 (2010-12-23 patchlevel 330) [i686-darwin10.6.0] | |
Matching against /^\w[\w-]{0,15}$/u | |
"" nil | |
"-" nil | |
"foo bar" nil | |
"sam" #<MatchData "sam"> | |
"⌘lee" #<MatchData "⌘lee"> | |
"I♥" #<MatchData "I♥"> | |
"яблочный" #<MatchData "яблочный"> | |
"quảtáo" #<MatchData "quảtáo"> | |
"☬☃☢☠☆☆☆" #<MatchData "☬☃☢☠☆☆☆"> | |
Matching against /^[\p{Ll}\p{Lu}][\p{Ll}\p{Lu}-]{0,15}$/u | |
"" nil | |
"-" nil | |
"foo bar" nil | |
"sam" nil | |
"⌘lee" nil | |
"I♥" nil | |
"яблочный" nil | |
"quảtáo" nil | |
"☬☃☢☠☆☆☆" nil | |
Matching against /^[\p{Ll}\p{Lu}\w][\p{Ll}\p{Lu}\w-]{0,15}$/u | |
"" nil | |
"-" nil | |
"foo bar" nil | |
"sam" #<MatchData "sam"> | |
"⌘lee" #<MatchData "⌘lee"> | |
"I♥" #<MatchData "I♥"> | |
"яблочный" #<MatchData "яблочный"> | |
"quảtáo" #<MatchData "quảtáo"> | |
"☬☃☢☠☆☆☆" #<MatchData "☬☃☢☠☆☆☆"> | |
Matching against /^\S{1,16}$/u | |
"" nil | |
"-" #<MatchData "-"> | |
"foo bar" nil | |
"sam" #<MatchData "sam"> | |
"⌘lee" #<MatchData "⌘lee"> | |
"I♥" #<MatchData "I♥"> | |
"яблочный" #<MatchData "яблочный"> | |
"quảtáo" #<MatchData "quảtáo"> | |
"☬☃☢☠☆☆☆" #<MatchData "☬☃☢☠☆☆☆"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby -v nick_matching.rb | |
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.6.0] | |
nick_matching.rb:6: warning: character class has duplicated range: /^[\p{Ll}\p{Lu}\w][\p{Ll}\p{Lu}\w-]{0,15}$/ | |
Matching against /^\w[\w-]{0,15}$/ | |
"" nil | |
"-" nil | |
"foo bar" nil | |
"sam" #<MatchData "sam"> | |
"⌘lee" nil | |
"I♥" nil | |
"яблочный" nil | |
"quảtáo" nil | |
"☬☃☢☠☆☆☆" nil | |
Matching against /^[\p{Ll}\p{Lu}][\p{Ll}\p{Lu}-]{0,15}$/ | |
"" nil | |
"-" nil | |
"foo bar" nil | |
"sam" #<MatchData "sam"> | |
"⌘lee" nil | |
"I♥" nil | |
"яблочный" #<MatchData "яблочный"> | |
"quảtáo" #<MatchData "quảtáo"> | |
"☬☃☢☠☆☆☆" nil | |
Matching against /^[\p{Ll}\p{Lu}\w][\p{Ll}\p{Lu}\w-]{0,15}$/ | |
"" nil | |
"-" nil | |
"foo bar" nil | |
"sam" #<MatchData "sam"> | |
"⌘lee" nil | |
"I♥" nil | |
"яблочный" #<MatchData "яблочный"> | |
"quảtáo" #<MatchData "quảtáo"> | |
"☬☃☢☠☆☆☆" nil | |
Matching against /^\S{1,16}$/ | |
"" nil | |
"-" #<MatchData "-"> | |
"foo bar" nil | |
"sam" #<MatchData "sam"> | |
"⌘lee" #<MatchData "⌘lee"> | |
"I♥" #<MatchData "I♥"> | |
"яблочный" #<MatchData "яблочный"> | |
"quảtáo" #<MatchData "quảtáo"> | |
"☬☃☢☠☆☆☆" #<MatchData "☬☃☢☠☆☆☆"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -w | |
# encoding: UTF-8 | |
[ /^\w[\w-]{0,15}$/u, # Existing | |
/^[\p{Ll}\p{Lu}][\p{Ll}\p{Lu}-]{0,15}$/u, # Won't work in 1.8 | |
/^[\p{Ll}\p{Lu}\w][\p{Ll}\p{Lu}\w-]{0,15}$/u, # Works in 1.8 and 1.9, but misses things like ⌘ in 1.9 | |
/^\S{1,16}$/u # Catches too much, would need janky blacklisting | |
].each do |pattern| | |
puts "\nMatching against #{pattern.inspect}" | |
["", "-", "foo bar", "sam", "⌘lee", "I♥", "яблочный", "quảtáo", "☬☃☢☠☆☆☆"].each do |nick| | |
puts "%-15s %s" % [nick.inspect, nick.match(pattern).inspect] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment