Skip to content

redmatter/go-globre

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Glob to RegExp

GoDoc Go Report Card License

A library for converting glob strings to regular expressions in golang.

Usage

import (
    "github.com/redmatter/go-globre/v2"
    "regexp"
)

urlGlob := "{http,https}://example.com/**"
// converts to ^(http|https):\/\/example\.com\/(?:(?:[^/]*(?:/|$))*)$
urlRe := globre.RegexFromGlob(
    urlGlob,
    globre.ExtendedSyntaxEnabled(true),
    globre.GlobStarEnabled(true),
    globre.WithDelimiter('/'),
)

// Compile the regexp
urlRegexp := regexp.MustCompile(urlRe)

// Match the url
if urlRegexp.MatchString("https://example.com/index.htm") {
    // do something
}

Options

The conversion to regexp can be modified using the following Option functions:

Option Default Value Description
WithDelimiter '/' Delimiter used for tokenising the compared string
ExtendedSyntaxEnabled false Enable extended globs, supporting classes, etc.
GlobStarEnabled false Enables "double-star" match for one or more tokens

License

Please see LICENSE and LICENSE-THIRD-PARTY.

About

Glob string to regexp string conversion in golang

Topics

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE-THIRD-PARTY.md

Stars

Watchers

Forks

Packages

No packages published

Languages