Posted 5 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.

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Author of this card:

Avatar
Emanuel De
Last edit:
4 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