method

match

Importance_2
match(expected) public

Given a Regexp or String, passes if actual.match(pattern)

Examples

  email.should match(/^([^\s]+)((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
  email.should match("@example.com")
Show source
Register or log in to add new notes.
April 22, 2011
0 thanks

Careful when comparing strings

Input String is treated as Regexp:

"*test*".should match "*test*" #=> fail
"*test*".should match ".*test.*" #=> pass

Regexp special characters inside input String can’t [be] escaped:

"*test*".should match "\*test\*" #=> fail
"*test*".should match /\*test*\/ #=> pass
April 24, 2011
0 thanks

Input strings are treated as regexp

Input strings are treated as regexp, but you can escape special regexp characters as usual:

"*test*".should match "\\*test\\*" #=> pass
"*test*".should match '\*test\*' #=> pass
"*test*".should match /\*test\*/ #=> pass