Std.Regex (Cure Standard Library v0.37.2)

View Source

Public verified Regex API and compatibility façade.

Packaging

Unlike the foundational Std.* modules, which live in lib/std/, the Regex family lives in lib/std_deps/regex/. This is deliberate: Regex is an embedded package — a self-contained, proof-heavy dependent library that is swept as its own compilation stage and bundled under priv/std_deps/regex/ (see Cure.Stdlib.Packages and Cure.Stdlib.Paths.embedded_source_dirs/0). Keeping it out of lib/std/ keeps the foundational sweep small and lets a caller opt out of the embedded-package stage entirely (embedded_packages: false). Std.Regex is still the public façade users import; only its source location differs.

Examples

use Std.Regex

matches(digit_class(false), "order 42")              # => true
split_default(digit_class(false), "a1b2c")           # => ["a", "b", "c"]
replace_literal(digit_class(false), "a1b2", "#")     # => "a#b#"

Summary

Functions

Drop the first count characters from values.

Take the first count characters from values.

Return true if any character in input is a newline under policy.

Slice a bounded lookbehind history from reversed_prefix up to literal_history_limit().

Take at most limit characters from the front of values.

Drop the last count characters from values.

Count the number of characters in values as an Int.

Return the maximum number of preceding characters retained for lookbehind assertions (9).

Return true if regex matches anywhere in input.

Look up the captured substring for name inside a NamedMatch.

Search a list of NamedCapture entries for the first entry matching name.

Extract the first-line-only flag from RegexOptions.

Extract the NewlinePolicy from RegexOptions.

Compile regex and match it against the entire input string, returning Some(value) on a full match or None() otherwise.

Match a NamedRegex against the entire input string, returning both the typed match result and its extracted named captures.

Match pattern against the entire input string using the verified engine and return its decoded Sem(shape) value if it matches.

Match a greedy prefix of input with regex, returning the matched value and remaining suffix.

Match a greedy prefix of input with regex given explicit start-of-subject, start-of-line, and preceding word-character boundary flags.

Match a prefix of input with regex using the given greedy mode, returning the matched value and unconsumed suffix.

Match a compiled RegexProgram against the entire input string and return its converted result value if it matches.

Prepend chars as a String onto rest, omitting empty parts when trimming is TrimEmptyParts.

Return true if regex is configured with the first-line-only (f) option.

Return the NewlinePolicy configured on regex, defaulting to AnyUnicodeNewline().

Replace every non-overlapping match of regex in input with the string returned by replacement.

Replace every non-overlapping match of regex in input with the fixed replacement string.

Splice replacement strings computed by replacement into input for each match in matches starting from cursor.

Drop count leading elements from a reversed character list and reverse the remaining prefix back to forward order.

Return true if two character lists have identical length and elements.

Find all non-overlapping matches of regex across input in left-to-right order.

Continue scanning candidate for non-overlapping matches of regex, advancing by one character after zero-length matches to guarantee progress.

Find the first leftmost match of regex anywhere in input.

Search candidate for the first match of regex starting at position, advancing character by character while respecting firstline_only and policy.

Find the first match of a NamedRegex anywhere in input, returning the Match together with its extracted named captures.

Split input on every match of regex using the given SplitOptions.

Return true if limit allows another split point.

Split input on every match of regex, excluding separators, keeping empty parts, and imposing no part limit.

Decrement the remaining split part count when limit is bounded.

Functions

character_list_drop(values: List(Char), count: Int) -> List(Char)

 fn character_list_drop(values: List(Char), count: Int) -> List(Char)

Drop the first count characters from values.

character_list_take(values: List(Char), count: Int) -> List(Char)

 fn character_list_take(values: List(Char), count: Int) -> List(Char)

Take the first count characters from values.

characters_contain_newline(input: List(Char), policy: NewlinePolicy) -> Bool

 fn characters_contain_newline(input: List(Char), policy: NewlinePolicy) -> Bool

Return true if any character in input is a newline under policy.

history_from_reversed_prefix(reversed_prefix: List(Char)) -> List(Char)

 fn history_from_reversed_prefix(reversed_prefix: List(Char)) -> List(Char)

Slice a bounded lookbehind history from reversed_prefix up to literal_history_limit().

history_take_limit(values: List(Char), limit: Nat) -> List(Char)

 fn history_take_limit(values: List(Char), limit: Nat) -> List(Char)

Take at most limit characters from the front of values.

list_drop_last(values: List(Char), count: Int) -> List(Char)

 fn list_drop_last(values: List(Char), count: Int) -> List(Char)

Drop the last count characters from values.

list_length(values: List(Char)) -> Int

 fn list_length(values: List(Char)) -> Int

Count the number of characters in values as an Int.

literal_history_limit() -> Nat

 fn literal_history_limit() -> Nat

Return the maximum number of preceding characters retained for lookbehind assertions (9).

matches(result: Type, regex: Regex(result), input: String) -> Bool

 fn matches(result: Type, regex: Regex(result), input: String) -> Bool

Return true if regex matches anywhere in input.

named_capture(name: String, named: NamedMatch(result)) -> Option(String)

 fn named_capture(name: String, named: NamedMatch(result)) -> Option(String)

Look up the captured substring for name inside a NamedMatch.

named_capture_lookup(name: String, captures: List(NamedCapture)) -> Option(String)

 fn named_capture_lookup(name: String, captures: List(NamedCapture)) -> Option(String)

Search a list of NamedCapture entries for the first entry matching name.

options_firstline(options: RegexOptions) -> Bool

 fn options_firstline(options: RegexOptions) -> Bool

Extract the first-line-only flag from RegexOptions.

options_newline_policy(options: RegexOptions) -> NewlinePolicy

 fn options_newline_policy(options: RegexOptions) -> NewlinePolicy

Extract the NewlinePolicy from RegexOptions.

parse_full(result: Type, regex: Regex(result), input: String) -> Option(result)

 fn parse_full(result: Type, regex: Regex(result), input: String) -> Option(result)

Compile regex and match it against the entire input string, returning Some(value) on a full match or None() otherwise.

parse_full_named(result: Type, shape: ShapeCode, named: NamedRegex(result, shape), input: String) -> Option(NamedParse(result))

 fn parse_full_named(result: Type, shape: ShapeCode, named: NamedRegex(result, shape), input: String) -> Option(NamedParse(result))

Match a NamedRegex against the entire input string, returning both the typed match result and its extracted named captures.

parse_pattern_full(shape: ShapeCode, pattern: Pattern(shape), input: String) -> Option(Sem(shape))

 fn parse_pattern_full(shape: ShapeCode, pattern: Pattern(shape), input: String) -> Option(Sem(shape))

Match pattern against the entire input string using the verified engine and return its decoded Sem(shape) value if it matches.

parse_prefix(result: Type, regex: Regex(result), input: String) -> Option(Tuple(result, String))

 fn parse_prefix(result: Type, regex: Regex(result), input: String) -> Option(Tuple(result, String))

Match a greedy prefix of input with regex, returning the matched value and remaining suffix.

parse_prefix_at(result: Type, regex: Regex(result), input: String, subject_start: Bool, line_start: Bool, previous_ascii_word: Bool, previous_unicode_word: Bool) -> Option(Tuple(result, String))

 fn parse_prefix_at(result: Type, regex: Regex(result), input: String, subject_start: Bool, line_start: Bool, previous_ascii_word: Bool, previous_unicode_word: Bool) -> Option(Tuple(result, String))

Match a greedy prefix of input with regex given explicit start-of-subject, start-of-line, and preceding word-character boundary flags.

parse_prefix_with(result: Type, regex: Regex(result), input: String, greedy: Bool) -> Option(Tuple(result, String))

 fn parse_prefix_with(result: Type, regex: Regex(result), input: String, greedy: Bool) -> Option(Tuple(result, String))

Match a prefix of input with regex using the given greedy mode, returning the matched value and unconsumed suffix.

parse_program_full(result: Type, program: RegexProgram(result), input: String) -> Option(result)

 fn parse_program_full(result: Type, program: RegexProgram(result), input: String) -> Option(result)

Match a compiled RegexProgram against the entire input string and return its converted result value if it matches.

pattern_prefix_program_at(result: Type, regex: Regex(result), input: List(Char), subject_start: Bool, line_start: Bool, previous_ascii_word: Bool, previous_unicode_word: Bool) -> Option(Tuple(result, List(Char)))

 fn pattern_prefix_program_at(result: Type, regex: Regex(result), input: List(Char), subject_start: Bool, line_start: Bool, previous_ascii_word: Bool, previous_unicode_word: Bool) -> Option(Tuple(result, List(Char)))

Match a greedy prefix of character list input with regex at explicit boundary flags.

pattern_prefix_program_at_position(result: Type, regex: Regex(result), input: List(Char), position: InitialPosition, history: List(Char)) -> Option(Tuple(result, List(Char)))

 fn pattern_prefix_program_at_position(result: Type, regex: Regex(result), input: List(Char), position: InitialPosition, history: List(Char)) -> Option(Tuple(result, List(Char)))

Match a greedy prefix of character list input with regex at position using bounded lookbehind history.

prepend_split_part(chars: List(Char), trimming: SplitTrimming, rest: List(String)) -> List(String)

 fn prepend_split_part(chars: List(Char), trimming: SplitTrimming, rest: List(String)) -> List(String)

Prepend chars as a String onto rest, omitting empty parts when trimming is TrimEmptyParts.

regex_firstline(result: Type, regex: Regex(result)) -> Bool

 fn regex_firstline(result: Type, regex: Regex(result)) -> Bool

Return true if regex is configured with the first-line-only (f) option.

regex_newline_policy(result: Type, regex: Regex(result)) -> NewlinePolicy

 fn regex_newline_policy(result: Type, regex: Regex(result)) -> NewlinePolicy

Return the NewlinePolicy configured on regex, defaulting to AnyUnicodeNewline().

replace(result: Type, regex: Regex(result), input: String, replacement: Function(Match(result), String)) -> String

 fn replace(result: Type, regex: Regex(result), input: String, replacement: Function(Match(result), String)) -> String

Replace every non-overlapping match of regex in input with the string returned by replacement.

replace_literal(result: Type, regex: Regex(result), input: String, replacement: String) -> String

 fn replace_literal(result: Type, regex: Regex(result), input: String, replacement: String) -> String

Replace every non-overlapping match of regex in input with the fixed replacement string.

replace_matches(result: Type, input: List(Char), cursor: Int, matches: List(Match(result)), replacement: Function(Match(result), String)) -> List(Char)

 fn replace_matches(result: Type, input: List(Char), cursor: Int, matches: List(Match(result)), replacement: Function(Match(result), String)) -> List(Char)

Splice replacement strings computed by replacement into input for each match in matches starting from cursor.

reverse_drop(values: List(Char), count: Int) -> List(Char)

 fn reverse_drop(values: List(Char), count: Int) -> List(Char)

Drop count leading elements from a reversed character list and reverse the remaining prefix back to forward order.

same_characters(left: List(Char), right: List(Char)) -> Bool

 fn same_characters(left: List(Char), right: List(Char)) -> Bool

Return true if two character lists have identical length and elements.

scan(result: Type, regex: Regex(result), input: String) -> List(Match(result))

 fn scan(result: Type, regex: Regex(result), input: String) -> List(Match(result))

Find all non-overlapping matches of regex across input in left-to-right order.

scan_from(result: Type, regex: Regex(result), candidate: List(Char), reversed_prefix: List(Char), position: InitialPosition, firstline_only: Bool, firstline_open: Bool, policy: NewlinePolicy) -> List(Match(result))

 fn scan_from(result: Type, regex: Regex(result), candidate: List(Char), reversed_prefix: List(Char), position: InitialPosition, firstline_only: Bool, firstline_open: Bool, policy: NewlinePolicy) -> List(Match(result))

Continue scanning candidate for non-overlapping matches of regex, advancing by one character after zero-length matches to guarantee progress.

search(result: Type, regex: Regex(result), input: String) -> Option(Match(result))

 fn search(result: Type, regex: Regex(result), input: String) -> Option(Match(result))

Find the first leftmost match of regex anywhere in input.

search_from(result: Type, regex: Regex(result), candidate: List(Char), reversed_prefix: List(Char), subject_start: Bool, line_start: Bool, previous_ascii_word: Bool, previous_unicode_word: Bool, firstline_only: Bool, policy: NewlinePolicy) -> Option(Match(result))

 fn search_from(result: Type, regex: Regex(result), candidate: List(Char), reversed_prefix: List(Char), subject_start: Bool, line_start: Bool, previous_ascii_word: Bool, previous_unicode_word: Bool, firstline_only: Bool, policy: NewlinePolicy) -> Option(Match(result))

Search candidate for a match of regex starting from explicit boundary booleans and a reversed prefix of already-consumed characters.

search_from_position(result: Type, regex: Regex(result), candidate: List(Char), reversed_prefix: List(Char), position: InitialPosition, firstline_only: Bool, policy: NewlinePolicy) -> Option(Match(result))

 fn search_from_position(result: Type, regex: Regex(result), candidate: List(Char), reversed_prefix: List(Char), position: InitialPosition, firstline_only: Bool, policy: NewlinePolicy) -> Option(Match(result))

Search candidate for the first match of regex starting at position, advancing character by character while respecting firstline_only and policy.

search_named(result: Type, shape: ShapeCode, named: NamedRegex(result, shape), input: String) -> Option(NamedMatch(result))

 fn search_named(result: Type, shape: ShapeCode, named: NamedRegex(result, shape), input: String) -> Option(NamedMatch(result))

Find the first match of a NamedRegex anywhere in input, returning the Match together with its extracted named captures.

split(result: Type, regex: Regex(result), input: String, options: SplitOptions) -> List(String)

 fn split(result: Type, regex: Regex(result), input: String, options: SplitOptions) -> List(String)

Split input on every match of regex using the given SplitOptions.

split_can_continue(limit: SplitLimit) -> Bool

 fn split_can_continue(limit: SplitLimit) -> Bool

Return true if limit allows another split point.

split_default(result: Type, regex: Regex(result), input: String) -> List(String)

 fn split_default(result: Type, regex: Regex(result), input: String) -> List(String)

Split input on every match of regex, excluding separators, keeping empty parts, and imposing no part limit.

split_matches(result: Type, input: List(Char), cursor: Int, matches: List(Match(result)), options: SplitOptions) -> List(String)

 fn split_matches(result: Type, input: List(Char), cursor: Int, matches: List(Match(result)), options: SplitOptions) -> List(String)

Slice input around precomputed matches starting at cursor according to options.

split_next_limit(limit: SplitLimit) -> SplitLimit

 fn split_next_limit(limit: SplitLimit) -> SplitLimit

Decrement the remaining split part count when limit is bounded.