Regex::MatchOptions
Inherits Enum / Comparable / Value / Object
Represents options passed to regex match methods such as Regex#match.
Constants
Force pattern anchoring at the start of the subject.
Force pattern anchoring at the end of the subject.
Unsupported with PCRE.
Disable JIT engine.
Unsupported with PCRE.
Do not check subject for valid UTF encoding.
This option is potentially dangerous and must only be used when the
subject is guaranteed to be valid (e.g. String#valid_encoding?).
Failing to do so can lead to undefined behaviour in the regex library
and may crash the entire process.
NOTE: String is supposed to be valid UTF-8, but this is not guaranteed or
enforced. Especially data originating from external sources should not be
trusted.
UTF validation is comparatively expensive, so skipping it can produce a significant performance improvement.
subject = "foo"
if subject.valid_encoding?
/foo/.match(subject, options: Regex::MatchOptions::NO_UTF_CHECK)
else
raise "Invalid UTF in regex subject"
end
A good use case is when the same subject is matched multiple times, UTF validation only needs to happen once.
This option has no effect if the pattern was compiled with
CompileOptions::MATCH_INVALID_UTF when using PCRE2 10.34+.