Last active
February 1, 2016 05:09
-
-
Save phluid61/67953b6aeb01c82d0c21 to your computer and use it in GitHub Desktop.
Ruby / Oniguruma case-insensitive non-word quirk
This file contains 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 re.rb | |
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux] | |
non-word: | |
/\W/ => [] | |
/\W/i => [] | |
/[\W]/ => [] | |
/[\W]/i => ["fF", "Ss"] | |
not word/leading word: | |
/^\w/ => ["f"] | |
/^\w/i => ["f"] | |
/[^\w]/ => [] | |
/[^\w]/i => [] | |
word: | |
/\w/ => ["f", "F", "f", "G", "S", "s", "o", "E", "k"] | |
/\w/i => ["f", "F", "f", "G", "S", "s", "o", "E", "k"] | |
/[\w]/ => ["f", "F", "f", "G", "S", "s", "o", "E", "k"] | |
/[\w]/i => ["f", "F", "f", "G", "S", "s", "o", "E", "k"] | |
not non-word/leading non-word: | |
/^\W/ => [] | |
/^\W/i => [] | |
/[^\W]/ => ["f", "F", "f", "G", "S", "s", "o", "E", "k"] | |
/[^\W]/i => ["f", "F", "f", "G", "S", "s", "o", "E", "k"] |
This file contains 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
$ jruby -v re.rb | |
jruby 9.0.4.0 (2.2.2) 2015-11-12 b9fb7aa OpenJDK 64-Bit Server VM 24.91-b01 on 1.7.0_91-b02 +jit [linux-amd64] | |
non-word: | |
/\W/ => [] | |
/\W/i => [] | |
/[\W]/ => [] | |
/[\W]/i => ["fF", "S", "s", "k"] | |
not word/leading word: | |
/^\w/ => ["f"] | |
/^\w/i => ["f"] | |
/[^\w]/ => [] | |
/[^\w]/i => [] | |
word: | |
/\w/ => ["f", "F", "f", "G", "S", "s", "o", "E", "k"] | |
/\w/i => ["f", "F", "f", "G", "S", "s", "o", "E", "k"] | |
/[\w]/ => ["f", "F", "f", "G", "S", "s", "o", "E", "k"] | |
/[\w]/i => ["f", "F", "f", "G", "S", "s", "o", "E", "k"] | |
not non-word/leading non-word: | |
/^\W/ => [] | |
/^\W/i => [] | |
/[^\W]/ => ["f", "F", "f", "G", "S", "s", "o", "E", "k"] | |
/[^\W]/i => ["f", "F", "f", "G", "o", "E"] |
This file contains 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
$string = 'fFfGSsoEk'.freeze | |
def demo re, desc | |
puts "#{desc}:" | |
print " /#{re}/ => "; p $string.scan(/#{re}/) | |
print " /#{re}/i => "; p $string.scan(/#{re}/i) | |
print " /[#{re}]/ => "; p $string.scan(/[#{re}]/) | |
print " /[#{re}]/i => "; p $string.scan(/[#{re}]/i) | |
puts '' | |
end | |
demo('\W', 'non-word') | |
demo('^\w', 'not word/leading word') | |
demo('\w', 'word') | |
demo('^\W', 'not non-word/leading non-word') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment