ogenregex

package
v0.56.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: Apache-2.0 Imports: 9 Imported by: 18

Documentation

Overview

Package ogenregex provides an interface to the regex engine.

JSON Schema specification prefers to use ECMA 262 regular expressions. However, Go's regex engine is based on RE2, which is a different engine. Also, Go's regex engine does not support lookbehind assertions, to ensure linear time matching.

This package provides unified interface to both engines. Go's regex engine is used by default, but if the regex is not supported, the dlclark/regexp2 would be used.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(pattern string) (string, bool)

Convert converts a ECMA-262 regular expression to Go's regular expression.

If the conversion is not possible, ("", false) is returned.

Types

type Regexp

type Regexp interface {
	Match(s []byte) (bool, error)
	MatchString(s string) (bool, error)
	String() string
}

Regexp is a regular expression interface.

func Compile

func Compile(exp string) (Regexp, error)

Compile compiles a regular expression.

NOTE: this function may compile the same expression multiple times and can be slow. Compile the expression once and reuse it.

func MustCompile

func MustCompile(exp string) Regexp

MustCompile compiles a regular expression and panics on error.

NOTE: this function may compile the same expression multiple times and can be slow. Compile the expression once and reuse it.

Jump to

Keyboard shortcuts

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