Narra

Reference

std/regex

std/regex

Regular expressions with a linear-time engine.

narra
import * as Regexes from "std/regex"

The guide teaches it in chapter 13, The standard library.

This page is generated by scripts/std/generate.nra from narrac query --json interface std/regex. Do not edit it.

Types

RegexError

narra
export struct RegexError derives Show, Equatable {
  position: int
  reason: string
}

Functions: compile, formatError.

Match

narra
export struct Match derives Show, Equatable {
  start: int
  end: int
  text: string
  groups: Array<Option<string>>
  names: Array<string>
}

Functions: find, findFrom, findAll, group, namedGroup, replaceWith.

Regex

narra
export struct Regex {
  source: string
  ops: Array<Op>
  firsts: Array<int>
  seconds: Array<int>
  ranges: Array<int>
  groupCount: int
  slotCount: int
  names: Array<string>
  prefix: string
  anchored: bool
}

Functions: compile, checked, matches, find, findFrom, findAll, replace, replaceAll, replaceWith, split.

Functions

compile

narra
export function compile(pattern: string): Result<Regex, RegexError> uses alloc

Effects: alloc.

checked

narra
export function checked(pattern: string): Regex uses alloc

Effects: alloc.

formatError

narra
export function formatError(error: RegexError): string uses alloc

Effects: alloc.

matches

narra
export function matches(regex: Regex, text: string): bool uses alloc

Effects: alloc.

find

narra
export function find(regex: Regex, text: string): Option<Match> from regex uses alloc

Effects: alloc.

findFrom

narra
export function findFrom(regex: Regex, text: string, start: int): Option<Match> from regex uses alloc

Effects: alloc.

findAll

narra
export function* findAll(regex: Regex, text: string): Generator<Match> uses alloc

Effects: alloc.

group

narra
export function group(found: Match, index: int): Option<string>

Effects: none.

namedGroup

narra
export function namedGroup(found: Match, name: string): Option<string>

Effects: none.

replace

narra
export function replace(regex: Regex, text: string, replacement: string): string uses alloc

Effects: alloc.

replaceAll

narra
export function replaceAll(regex: Regex, text: string, replacement: string): string uses alloc

Effects: alloc.

replaceWith

narra
export function replaceWith<effect E>(regex: Regex, text: string, change: (Match) => string uses E): string uses E, alloc

Effects: E, alloc.

split

narra
export function split(regex: Regex, text: string): Array<string> uses alloc

Effects: alloc.