Wildcard v0.2.1 Wildcard View Source
Provides functions for dealing with wildcard expressions which are intended to match agains strings.
A wildcard expression is a string that contains * characters which indicate
that any text can be substituted at the location of the * characters. An
example of a wildcard expression would be "ch*se", which would match
"cheese", but not "cats".
Options
The following options can be specified for the functions in the Wildcard module:
match_type- determines what will be matched by a wildcard character. The default is:one_or_more:one_or_more- Matches one or more characters.:zero_or_more- Matches any number of characters or none at all.:one- Matches exactly one character.
Link to this section Summary
Functions
Returns a boolean indicating whether the given string matches against a given wildcard expression
Converts an expression that can contain wildcards into a regex that can be used to match text
Link to this section Functions
matches?(Binary.t(), Binary.t(), Keyword.t()) :: boolean()
Returns a boolean indicating whether the given string matches against a given wildcard expression.
Examples
iex> Wildcard.matches?("twelve monkeys", "*cat*")
false
iex> Wildcard.matches?("man bear pig", "man*pig")
true
Converts an expression that can contain wildcards into a regex that can be used to match text.
The resulting regex does not anchor to the beginning or end of the string using ^ or $. All non-wildcard text in the given expression is converted to raw text.
Examples
iex> Wildcard.to_regex("man*pig")
~r/man.+pig/
iex> Wildcard.to_regex("man*pig", match_type: :zero_or_more)
~r/man.*pig/
iex> Wildcard.to_regex("man****pig", match_type: :one)
~r/man....pig/