pattern

package
v2.0.5-main.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pattern compiles the regular expressions tokenizers cut text with, written for Oniguruma (Hugging Face tokenizers) or for Rust's fancy-regex (tiktoken, Mistral's tekken, llama.cpp), into what regexp2 runs with the same matches

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile

func Compile(expr string, dialect Dialect) (*regexp2.Regexp, error)

Expression compiled for regexp2

func Find

func Find(re *regexp2.Regexp, s string) ([][2]int, error)

Byte ranges of every match of the expression in s, in order and without overlap

func Translate

func Translate(expr string, dialect Dialect) (string, error)

The expression in the syntax regexp2 compiles: possessive quantifiers as atomic groups, ignored case spelled out as classes of every case Unicode folds together, and for Rust's syntax $ at the end of the text

Types

type Dialect

type Dialect int

Syntax an expression is written in

const (
	// Oniguruma as Hugging Face tokenizers compiles it: ^ and $ at the ends of lines, \h a hex digit, POSIX brackets and class
	// intersections
	Oniguruma Dialect = iota
	// Rust's fancy-regex: ^ and $ at the ends of the whole text
	Fancy
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL