It matches string to a regular expression.
'hello' =~ /^h/ # => 0
If there is no match, it will return nil
. If you pass it invalid arguments (ie, left or right-hand sides are not correct), it will either throw a TypeError
or return false
.
Related Contents:
- What does map(&:name) mean in Ruby?
- What does ||= (or-equals) mean in Ruby?
- Difference between “or” and || in Ruby? [duplicate]
- What is Ruby’s double-colon `::`?
- What is the Ruby (spaceship) operator?
- What does the (unary) * operator do in this Ruby code?
- Why doesn’t Ruby support i++ or i– (increment/decrement operators)?
- What’s the difference between equal?, eql?, ===, and ==?
- Difference between “and” and && in Ruby?
- No increment operator (++) in Ruby? [duplicate]
- Understanding the “||” OR operator in If conditionals in Ruby
- What does the unary question mark (?) operator do?
- Is there any wisdom behind “and”, “or” operators in Ruby?
- list of ruby operators that can be overridden/implemented
- Why do Ruby setters need “self.” qualification within the class?
- Why use Ruby’s attr_accessor, attr_reader and attr_writer?
- How to generate a random string in Ruby
- ruby floating point errors
- What does the “===” operator do in Ruby? [duplicate]
- What does !! mean in ruby?
- Executing code for every method call in a Ruby module
- Getting the Hostname or IP in Ruby on Rails
- Is there an efficient way to perform hundreds of text substitutions in Ruby?
- What’s the difference between a proc and a lambda in Ruby?
- Best way to escape and unescape strings in Ruby?
- Is it possible to have Methods inside Methods?
- Find indices of elements that match a given condition
- Ruby – print the variable name and then its value
- How to match all occurrences of a regular expression in Ruby
- Using ‘return’ in a Ruby block
- Sort hash by key, return hash in Ruby
- Is it good style to explicitly return in Ruby?
- Ruby: require vs require_relative – best practice to workaround running in both Ruby =1.9.2
- Difference between ‘..’ (double-dot) and ‘…’ (triple-dot) in range generation?
- What are the restrictions for method names in Ruby?
- How to check if a URL is valid
- How does the magic comment ( # Encoding: utf-8 ) in ruby work?
- How can I have ruby logger log output to stdout as well as file?
- Ruby obfuscator [duplicate]
- Strange \n in base64 encoded string in Ruby
- How to convert a string to a constant in Ruby?
- Extract a substring from a string in Ruby using a regular expression
- Performance of Arrays and Hashes in Ruby
- Comparing ruby hashes [duplicate]
- Why are symbols in Ruby not thought of as a type of variable?
- String interpolation in Ruby doesn’t work?
- How do I use define_method to create class methods?
- How to install therubyracer gem on 10.10 Yosemite?
- Checking if a variable is defined in SASS
- Using layouts in HAML files independently of Rails