Skip to content

Instantly share code, notes, and snippets.

@tak1n
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tak1n/8865959 to your computer and use it in GitHub Desktop.
Save tak1n/8865959 to your computer and use it in GitHub Desktop.
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