Last active
August 29, 2015 13:56
-
-
Save tak1n/8865959 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
BEG_REGEXP = /\G(?:\ | |
(?# 1: SPACE )( +)|\ | |
(?# 2: NIL )(NIL)(?=[\x80-\xff(){ \x00-\x1f\x7f%*#{'"'}\\\[\]+])|\ | |
(?# 3: NUMBER )(\d+)(?=[\x80-\xff(){ \x00-\x1f\x7f%*#{'"'}\\\[\]+])|\ | |
(?# 4: ATOM )([^\x80-\xff(){ \x00-\x1f\x7f%*#{'"'}\\\[\]+]+)|\ | |
(?# 5: QUOTED )"((?:[^\x00\r\n"\\]|\\["\\])*)"|\ | |
(?# 6: LPAR )(\()|\ | |
(?# 7: RPAR )(\))|\ | |
(?# 8: BSLASH )(\\)|\ | |
(?# 9: STAR )(\*)|\ | |
(?# 10: LBRA )(\[)|\ | |
(?# 11: RBRA )(\])|\ | |
(?# 12: LITERAL )\{(\d+)\}\r\n|\ | |
(?# 13: PLUS )(\+)|\ | |
(?# 14: PERCENT )(%)|\ | |
(?# 15: CRLF )(\r\n)|\ | |
(?# 16: EOF )(\z))/ni | |
# (?# 3: NUMBER ) removed - MRI && rbx throws error | |
# (?# 4: ATOM ) removed - MRI && rbx throws error | |
# (?# 16: EOF ) removed - both returns 0 (Fixnum) | |
str = "K" | |
searched = str.index(BEG_REGEXP) | |
searched2 = str.index("K") | |
puts "return value for regex: #{searched}" | |
puts "return class for regex: #{searched.class}" | |
puts "return value for string: #{searched2}" | |
puts "return value for string: #{searched2.class}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment