The Regexp
is the class for regular expression matching.
Regular expression literals are enclosed by slashes like:
/^this is regexp/
In other way, you can create the regular expression object using:
Regexp.new(string)
Object
compile(string[, casefold])
new(string[, casefold])
Compiles the string into a regular expression object. If
second argument given, and its value is not nil
, then the
created regexp object becomes case-insensitive.
quote(string)
Insert escape characters before regular expression special characters
in the string
. Returns the newly created strings.
self =~ string
self === string
Returns an index of the matching place in the string, if matched.
Returns nil
if not matched. The index of the first
character is 0.
~ self
Matches with the value of the default variable ($_
).
Behaves like:
$_ =~ self