struct

BSON::Regex

Inherits Struct < Value < Object

BSON regular expression: a pattern C string and an options C string.

This type does not compile the pattern. Unusual or invalid patterns stay as text and can round-trip. Call #to_regex when you want a Crystal Regex.

Constructors

new(pattern : String, options : String = "")

Create from a pattern and option letters. Letters are stored unique and in alphabetical order, as required by the BSON spec.

Source
new(regex : ::Regex)

Create from a Crystal regex. Option letters are the BSON letters only.

Source

Class methods

crystal_options(ptr : Pointer(UInt8), size : Int) : ::Regex::Options

Map BSON option letters to Crystal flags. Unknown letters are ignored.

Source
crystal_options(options : String) : ::Regex::Options
Source
letters_from(options : ::Regex::Options) : String

Map Crystal regex flags to BSON letters in alphabetical order: i, m, s, u, x.

Source
sort_options(options : String) : String

Unique option letters in alphabetical order. Extra letters are kept.

Source
write_letters(io : IO, options : ::Regex::Options) : Nil

Write BSON regex option letters in alphabetical order: i, m, s, u, x.

Source

Instance methods

==(other : ::Regex) : Bool
Source
==(other : self) : Bool
Source
options
Source
pattern
Source
to_canonical_extjson(builder : JSON::Builder)

Serialize to a canonical extended json representation.

NOTE: see https://github.com/mongodb/specifications/blob/master/source/extended-json.rst

Source
to_json(builder : JSON::Builder)
Source
to_regex

Compile as a Crystal Regex. Raises if the pattern is not valid PCRE.

Source
to_regex?

Compile as a Crystal Regex, or nil if the pattern is not valid PCRE.

Source