globre

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2025 License: MIT Imports: 0 Imported by: 0

README

Glob to RegExp

Glob string to regexp string conversion in golang

Usage

package example

urlGlob := "{http,https}://example.com/**"
// converts to ^(http|https):\/\/example\.com\/(?:(?:[^/]*(?:/|$))*)$
urlRe := globre.RegexFromGlobWithOptions(
	urlGlob, globre.Options{
		Extended:  true,
		GlobStar:  true,
		Delimiter: '/',
	})
urlRegexp := regexp.MustCompile(urlRe)
urlRegexp.MatchString("https://example.com/index.htm")

Options

The conversion to regexp can be modified using globre.Options.

Attr Type Desc
Delimiter rune Delimiter used for tokenising the compared string
Extended bool Enable extended globs, supporting classes, etc.
GlobStar bool Enables "double-star" match for one or more tokens

License

Please see LICENSE and LICENSE-THIRD-PARTY.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegexFromGlob

func RegexFromGlob(glob string) string

RegexFromGlob converts the glob string into a regexp string with options "extended" & "glob-star" enabled, and with the default delimiter '/'

func RegexFromGlobWithOptions

func RegexFromGlobWithOptions(glob string, config Options) string

RegexFromGlobWithOptions converts glob to regexp string with the given options

Types

type Options

type Options struct {
	Extended  bool
	GlobStar  bool
	Delimiter rune
}

Jump to

Keyboard shortcuts

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