wildmatch

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2021 License: MIT Imports: 1 Imported by: 9

README

wildmatch go

GoDev Sourcegraph Go Report Card GitHub Workflow Status

golang library of the original rust wildmatch library.

go get github.com/becheran/wildmatch-go

Match strings against a simple wildcard pattern. Tests a wildcard pattern p against an input string s. Returns true only when p matches the entirety of s.

See also the example described on wikipedia for matching wildcards.

  • ? matches exactly one occurrence of any character.
  • * matches arbitrary many (including zero) occurrences of any character.
  • No escape characters are defined.

For example the pattern ca? will match cat or car. The pattern https://* will match all https urls, such as https://google.de or https://github.com/becheran/wildmatch.

The library only depends on the go standard library.

Documentation

Overview

Package wildmatch used to match strings against a simple wildcard pattern. Tests a wildcard pattern `p` against an input string `s`. Returns true only when `p` matches the entirety of `s`.

See also the example described on [wikipedia](https://en.wikipedia.org/wiki/Matching_wildcards) for matching wildcards.

No escape characters are defined.

- `?` matches exactly one occurrence of any character. - `*` matches arbitrary many (including zero) occurrences of any character.

Examples matching wildcards: ``` go import "github.com/becheran/wildmatch-go" wildmatch.NewWildMatch("cat").IsMatch("cat") wildmatch.NewWildMatch("*cat*").IsMatch("dog_cat_dog") wildmatch.NewWildMatch("c?t").IsMatch("cat") wildmatch.NewWildMatch("c?t").IsMatch("cot") ``` Examples not matching wildcards: ``` go import "github.com/becheran/wildmatch-go" wildmatch.NewWildMatch("dog").IsMatch("cat") wildmatch.NewWildMatch("*d").IsMatch("cat") wildmatch.NewWildMatch("????").IsMatch("cat") wildmatch.NewWildMatch("?").IsMatch("cat") ```

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WildMatch

type WildMatch struct {
	// contains filtered or unexported fields
}

/ WildMatch is a wildcard matcher used to match strings.

func NewWildMatch

func NewWildMatch(pattern string) *WildMatch

NewWildMatch creates new pattern matcher.

func (*WildMatch) IsMatch

func (w *WildMatch) IsMatch(input string) bool

IsMatch indicates whether the matcher finds a match in the input string.

func (*WildMatch) String

func (w *WildMatch) String() string

Jump to

Keyboard shortcuts

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