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 web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
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)