enum

Regex::MatchOptions

Inherits Enum / Comparable / Value / Object

Represents options passed to regex match methods such as Regex#match.

Constants

ANCHORED = 1

Force pattern anchoring at the start of the subject.

ENDANCHORED = 2

Force pattern anchoring at the end of the subject.

Unsupported with PCRE.

NO_JIT = 4

Disable JIT engine.

Unsupported with PCRE.

NO_UTF_CHECK = 8

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+.

None = 0
All = 15

Instance methods

anchored?

Returns true if this enum value contains ANCHORED

Source
endanchored?

Returns true if this enum value contains ENDANCHORED

Source
no_jit?

Returns true if this enum value contains NO_JIT

Source
no_utf_check?

Returns true if this enum value contains NO_UTF_CHECK

Source
none?
Source