Posted 3 months ago. Visible to the public.

Ruby: Return boolean for regex comparison

A collection of code snippets which return a boolean value for a regex comparison.

Copy
regexp.match?(string) # Recommended for Ruby >= 2.4 !!(string =~ regexp) # Recommended for older Rubies regexp === string !(regexp !~ string)

The Ruby 2.4 method Regexp#match? does not set globals like $~ or $1, so it should be more performant.

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for old versions of Ruby on Rails (3.2 and 2.3).

Author of this card:

Avatar
Emanuel De
Last edit:
2 months ago
by Henning Koch
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Emanuel De to makandropedia