Help us shape the future of Go! Take the 2026 Go Developer Survey

glob4go

package module
v0.0.0-...-e150665 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2017 License: MIT Imports: 1 Imported by: 1

README

glob4go

Build Status

A lightweight glob wildcard pattern matching utility for Go, when regex is an overkill

Installation

go get github.com/co89757/glob4go 

Supported Glob feature

The glob syntax is largely similar to UNIX globbing execept for a few unsupported syntax

  • * :matches any number of characters
  • ? :matches a single character
  • [...] :matches a range/group of characters. For example, [0-9] matches any single-digit number, [axz] matches any character in 'a','x','z'
  • [^...] :inverse range/group match. The inverse of the above range match case. It matches any character not in the range
  • all keywords above can be escaped by \, i.e. \? matches a literal ?

Example

Currently, the API of the pacakge is really simple:

glob4go.Glob(pattern, str []byte, ignoreCase bool) 

Here is an example usage

import (
  "github.com/co89757/glob4go"
)
func globExample(){
  var match bool 
pattern := []byte("abcd[0-9]?")
s1 := []byte("abcd8e")
//case sensitive match
match = glob4go.Glob(pattern,s1,false) // true, it is a match 

s2 := []byte("AbCd8e")
match = glob4go.Glob(pattern, s2, true) // true, it is a match when ignore case 
}

TO-DO

  • Performance and benchmarking
  • Add unicode support

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Glob

func Glob(pattern []byte, s []byte, nocase bool) bool

Glob matches a string against a glob wildcard pattern, nocase flag is for case-insensitive match

Types

This section is empty.

Jump to

Keyboard shortcuts

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