Class: Regexp

Inherits:
Object show all
Defined in:
lib/mini_sanity/match.rb

Instance Method Summary collapse

Instance Method Details

#match!(str, pos = 0) ⇒ MatchData

Like Regexp#match, but raises an exception if the match fails.

Examples:

/^([^@]+)@(.+)$/.match!("[email protected]")  # === MatchData
/^([^@]+)@(.+)$/.match!("@user")             # raises exception

Parameters:

  • String to search

  • (defaults to: 0)

    Position in str to search from

Returns:

Raises:

  • if the Regexp does not match str



53
54
55
# File 'lib/mini_sanity/match.rb', line 53

def match!(str, pos = 0)
  str.match!(self, pos)
end