Hacker News new | past | comments | ask | show | jobs | submit login

Ruby 2.4 adds a new #match? method for regular expressions which is three times faster than any Regexp method in Ruby 2.3:

Why does Ruby have 4 different regexp match functions?

Regexp#match?: 2630002.5 i/s Regexp#===: 872217.5 i/s - 3.02x slower Regexp#=~: 859713.0 i/s - 3.06x slower Regexp#match: 539361.3 i/s - 4.88x slower




So there is choice of course.

match returns match data, and sets the $~ variable

=== returns true or false, setting the $~ variable

=~ returns integer (position) or nil, setting $~

The newest one match? returns a boolean, not setting $~


Also, === is the method used in case statement matching.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: