Read more

Ruby: Return boolean for regex comparison

Emanuel
February 09, 2017Software engineer at makandra GmbH

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

regexp.match?(string) # Recommended for Ruby >= 2.4

!!(string =~ regexp)  # Recommended for older Rubies

regexp === string

!(regexp !~ string)
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

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

Posted by Emanuel to makandra dev (2017-02-09 14:29)