View Source PathGlob (PathGlob v0.2.0)

Implements glob matching using the same semantics as Path.wildcard/2, but without any filesystem interaction.

Link to this section Summary

Functions

Compiles glob to a Regex.

Returns whether or not path matches the glob.

Link to this section Functions

Link to this function

compile(glob, opts \\ [])

View Source
@spec compile(String.t(), [{:match_dot, boolean()}]) :: Regex.t()

Compiles glob to a Regex.

Raises ArgumentError if glob is invalid.

examples

Examples

iex> PathGlob.compile("{lib,test}/*")
~r{^(lib|test)/([^\./]|(?<=[^/])\.)*$}

iex> PathGlob.compile("{lib,test}/path_*.ex", match_dot: true)
~r{^(lib|test)/path_[^/]*\.ex$}
Link to this function

match?(path, glob, opts \\ [])

View Source
@spec match?(String.t(), String.t(), [{:match_dot, boolean()}]) :: boolean()

Returns whether or not path matches the glob.

The glob is first parsed and compiled as a regular expression. If you're using the same glob multiple times in performance-critical code, consider using compile/1 and caching the result.

examples

Examples

iex> PathGlob.match?("lib/path_glob.ex", "{lib,test}/path_*.ex")
true

iex> PathGlob.match?("lib/.formatter.exs", "lib/*", match_dot: true)
true