pattern

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchAnt

func MatchAnt(pattern, s string) bool

MatchAnt reports whether s matches the given Ant-style glob pattern.

The pattern uses "/" as a segment separator. Wildcards:

  • ? matches exactly one character within a single segment
  • * matches zero or more characters within a single segment
  • ** matches zero or more complete segments (including none)

Common uses include URL paths, file paths, config key hierarchies, and any dot- or slash-delimited namespace (e.g. "org.**.service.*").

Examples:

MatchAnt("/api/*",        "/api/users")       // true  – single segment wildcard
MatchAnt("/api/**",       "/api/v1/users")    // true  – multi-segment wildcard
MatchAnt("/user/?",       "/user/a")          // true  – single char wildcard
MatchAnt("/user/?",       "/user/ab")         // false – ? matches exactly one char
MatchAnt("**.log",        "app.service.log")  // true  – suffix match across segments
MatchAnt("config/*/host", "config/db/host")   // true  – middle segment wildcard

func MatchRegex

func MatchRegex(regexPattern, path string) bool

MatchRegex reports whether path matches the given regular expression. The pattern is automatically anchored (^ and $) so partial matches are rejected. Returns false if the pattern fails to compile.

func MatchWildcard

func MatchWildcard(pattern, s string) bool

MatchWildcard reports whether s matches pattern using ? and * wildcards.

Unlike MatchAnt, this operates on a flat string with no segment semantics — * can match across any character including "/" or ".".

Useful for simple shell-style glob matching on filenames, identifiers, or any string where segment boundaries are irrelevant.

  • ? matches exactly one character
  • * matches zero or more characters

Examples:

MatchWildcard("foo*",   "foobar")    // true
MatchWildcard("f?o",    "foo")       // true
MatchWildcard("*.json", "data.json") // true
MatchWildcard("*.json", "a/b.json")  // true  – * crosses "/"

Types

This section is empty.

Jump to

Keyboard shortcuts

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