Cs169x

From Wiki2
Revision as of 08:26, 12 August 2013 by Tim (talk | contribs) (Created page with ""string", %Q{string}, 'string', %q{string} a=41 ; "The answer is #{a+1}" *match a string against a regexp: "fox@berkeley.EDU" =~ /(.*)@(.*)\.edu$/i /(.*)@(.*)\.edu$/i =~ "fox@...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

"string", %Q{string}, 'string', %q{string} a=41 ; "The answer is #{a+1}"

  • match a string against a regexp:

"fox@berkeley.EDU" =~ /(.*)@(.*)\.edu$/i /(.*)@(.*)\.edu$/i =~ "fox@berkeley.EDU"

  • If no match, value is false
  • If match, value is non-false, and $1...$n capture

parenthesized groups ($1 == 'fox', $2 == 'berkeley') /(.*)$/i or %r{(.*)$}i or Regexp.new('(.*)$', Regexp::IGNORECASE)