Defining a Regexp

suggest change

A Regexp can be created in three different ways in Ruby.

#The following forms are equivalent
regexp_slash = /hello/
regexp_bracket = %r{hello}
regexp_new = Regexp.new('hello')

string_to_match = "hello world!"

#All of these will return a truthy value
string_to_match =~ regexp_slash    # => 0
string_to_match =~ regexp_bracket  # => 0
string_to_match =~ regexp_new      # => 0

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Regular Expressions and regex based operations:
*Defining a Regexp

Table Of Contents