verbalex v0.3.0 Verbalex View Source
Documentation for Verbalex.
Link to this section Summary
Functions
Matches any character. Equivalent to "."
Match any of the characters in a given character class, classes, or string - provided as opts.
Inverse of anything_in/2
.
Wraps a regex string in a non-capturing group. This facilitates easy application of things like quantifiers or backreferences to the entirety of a given expression.
Wraps a regex string in a capturing group.
Wraps a regex string in a named-capturing group. To be utilised with Regex.named_captures(regex, string, opts \\ [])
.
Matches a carriage return character. Equivalent to "\r".
Matches a digit (0-9). Equivalent to "\d".
Express the end of a line regex anchor. Translates to '$'.
Express a string literal to be matched exactly and wraps in a non-capturing group.
Alias of then/3
for readability semantics, as 'find' is a makes more sense when placed at the beginning of a pipe chain.
Takes a regex string and applies a lookahead condition. Escapes special characters by default.
Takes a regex string and applies a negative lookahead condition. Escapes special characters by default.
Takes a regex string and applies a negative lookbehind condition. Escapes special characters by default.
Takes a regex string and applies a lookbehind condition. Escapes special characters by default.
Matches a linebreak character. Equivalent to "\n".
Express a pattern as being optional to match.
Matches anything but a digit (0-9). Equivalent to "\D".
Matches anything but whitespace character - includes tabs and line breaks.
Matches anything but a 'word', equivalent to [^a-zA-Z0-9_]
Specify the number of expected occurences to be found on a given expression.
Specify the minimum number of expected occurences to be found on a given expression.
Specify the range of expected occurences to be found on a given expression.
Express a pattern will occur one or more times.
Takes in a list of regex strings, and inserts an or operator between each of them.
Does not escape characters by default to preference OR-ing complex expressions and encourage composition.
Special character escaping is available via the escape: true
option.
Express the start of a line regex anchor. Translates to '^'.
Matches a tab character. Equivalent to "\t".
Express a string literal to be matched exactly and wraps in a non-capturing group. Escapes special characters by default.
Turn off character escapes with the escape: false
option.
Matches a whitespace character - includes tabs and line breaks.
Matches a 'word', equivalent to [a-zA-Z0-9_]
Matches a 'word boundary' - a word bounary is the position between a word and non-word character (0-9A-Za-z_]
).
It is commonly thought of as matching the beginning or end of a string.
Express a pattern will occur zero or more times.
Link to this section Types
character_class()
View Source
character_class() ::
:alnum
| :alpha
| :ascii
| :blank
| :cntrl
| :digit
| :graph
| :lower
| :print
| :punct
| :space
| :upper
| :word
| :xdigit
character_class() :: :alnum | :alpha | :ascii | :blank | :cntrl | :digit | :graph | :lower | :print | :punct | :space | :upper | :word | :xdigit
set_opt()
View Source
set_opt() ::
{:class, character_class()}
| {:classes, [character_class()]}
| {:string, String.t()}
set_opt() :: {:class, character_class()} | {:classes, [character_class()]} | {:string, String.t()}
set_opts()
View Source
set_opts() :: [set_opt()]
set_opts() :: [set_opt()]
Link to this section Functions
anything(before \\ "") View Source
Matches any character. Equivalent to "."
anything_in(before, opts \\ []) View Source
Match any of the characters in a given character class, classes, or string - provided as opts.
The supported class names (provided with class: ...
, or classes: [...]
) are:
:alnum
- Letters and digits:alpha
- Letters:ascii
- Character codes 0-127:blank
- Space or tab only:cntrl
- Control characters:digit
- Decimal digits (same as \d):graph
- Printing characters, excluding space:lower
- Lowercase letters:print
- Printing characters, including space:punct
- Printing characters, excluding letters, digits, and space:space
- Whitespace (the same as \s from PCRE 8.34):upper
- Uppercase letters:word
- "Word" characters (same as \w):xdigit
- Hexadecimal digits
Examples
iex> alias Verbalex, as: Vlx
iex> "" |> Vlx.anything_in(class: :alnum, string: "._%+-") |> Vlx.one_or_more()
"[[:alnum:]._%+-]+"
iex> alias Verbalex, as: Vlx
iex> "" |> Vlx.anything_in(classes: [:lower, :punct])
"[[:lower:][:punct:]]"
anything_not_in(before, opts \\ []) View Source
Inverse of anything_in/2
.
atomize(string) View Source
Wraps a regex string in a non-capturing group. This facilitates easy application of things like quantifiers or backreferences to the entirety of a given expression.
Examples
iex> alias Verbalex, as: Vlx
iex> protocol = Vlx.find("http") |> Vlx.maybe("s") |> Vlx.then("://") |> Vlx.atomize()
iex> Vlx.maybe(protocol) |> Vlx.then("www.")
"(?:(?:http)s?(?:://))?(?:www\\.)"
atomize(before, string) View Source
capture(before \\ "") View Source
capture(before, string, opts \\ []) View Source
Wraps a regex string in a capturing group.
Examples
iex> alias Verbalex, as: Vlx
iex> pattern = Vlx.find("this") |> Vlx.then("that")
iex> Vlx.capture(pattern)
"((?:this)(?:that))"
capture_as(before, as) View Source
Wraps a regex string in a named-capturing group. To be utilised with Regex.named_captures(regex, string, opts \\ [])
.
Examples
iex> alias Verbalex, as: Vlx
iex> Vlx.find("http") |> Vlx.maybe("s") |> Vlx.then("://") |> Vlx.capture_as("protocols")
"(?<protocols>(?:http)s?(?::\/\/))"
carriage_return(before \\ "") View Source
Matches a carriage return character. Equivalent to "\r".
digit(before \\ "") View Source
Matches a digit (0-9). Equivalent to "\d".
end_of_line(before \\ "") View Source
Express the end of a line regex anchor. Translates to '$'.
Examples
iex> alias Verbalex, as: Vlx
iex> Vlx.find("far, far, away.") |> Vlx.end_of_line() |> Regex.compile!()
~r/(?:far,\ far,\ away\.)$/
find(string) View Source
find(before, string, opts \\ []) View Source
Express a string literal to be matched exactly and wraps in a non-capturing group.
Alias of then/3
for readability semantics, as 'find' is a makes more sense when placed at the beginning of a pipe chain.
NOTE: Under the current implementation, when using the escape: false
option in
pipe chains beginning with find
, an empty string must be provided as the first value.
Examples
iex> alias Verbalex, as: Vlx
iex> Vlx.find("needle") |> Vlx.if_preceded_by("hay") |> Vlx.if_followed_by("stack")
"(?<=hay)(?:needle)(?=stack)"
if_followed_by(before, string, opts \\ []) View Source
Takes a regex string and applies a lookahead condition. Escapes special characters by default.
Examples
iex> alias Verbalex, as: Vlx
iex> Vlx.find("sentence") |> Vlx.if_followed_by(".") |> Vlx.capture()
"((?:sentence)(?=\\.))"
if_not_followed_by(before, string, opts \\ []) View Source
Takes a regex string and applies a negative lookahead condition. Escapes special characters by default.
Examples
iex> alias Verbalex, as: Vlx
iex> Vlx.find("good") |> Vlx.if_not_followed_by("bye") |> Vlx.capture()
"((?:good)(?!bye))"
if_not_preceded_by(before, string, opts \\ []) View Source
Takes a regex string and applies a negative lookbehind condition. Escapes special characters by default.
Examples
iex> alias Verbalex, as: Vlx
iex> Vlx.digit() |> Vlx.if_not_preceded_by("%") |> Vlx.capture()
"((?<!%)\d)"
if_preceded_by(before, string, opts \\ []) View Source
Takes a regex string and applies a lookbehind condition. Escapes special characters by default.
Examples
iex> alias Verbalex, as: Vlx
iex> Vlx.digit() |> Vlx.if_preceded_by("$") |> Vlx.capture()
"((?<=\\$)\d)"
linebreak(before \\ "") View Source
Matches a linebreak character. Equivalent to "\n".
maybe(before, string \\ "", opts \\ []) View Source
Express a pattern as being optional to match.
Examples
iex> alias Verbalex, as: Vlx
iex> Vlx.find("colo") |> Vlx.maybe("u") |> Vlx.then("r")
"(?:colo)u?(?:r)"
not_digit(before \\ "") View Source
Matches anything but a digit (0-9). Equivalent to "\D".
not_whitespace(before \\ "") View Source
Matches anything but whitespace character - includes tabs and line breaks.
not_word(before \\ "") View Source
Matches anything but a 'word', equivalent to [^a-zA-Z0-9_]
occurs(before, n) View Source
Specify the number of expected occurences to be found on a given expression.
Examples
iex> alias Verbalex, as: Vlx
iex> Vlx.digit() |> Vlx.capture() |> Vlx.occurs(4)
"(\d){4}"
occurs_at_least(before, n) View Source
Specify the minimum number of expected occurences to be found on a given expression.
Examples
iex> alias Verbalex, as: Vlx
iex> Vlx.digit() |> Vlx.capture() |> Vlx.occurs_at_least(2)
"(\d){2,}"
occurs_in_range(before, min, max) View Source
Specify the range of expected occurences to be found on a given expression.
Examples
iex> alias Verbalex, as: Vlx
iex> Vlx.digit() |> Vlx.capture() |> Vlx.occurs_in_range(3, 6)
"(\d){3,6}"
one_or_more(before, string \\ "", opts \\ []) View Source
Express a pattern will occur one or more times.
Examples
iex> alias Verbalex, as: Vlx
iex> "" |> Vlx.anything_in(class: :alnum) |> Vlx.one_or_more()
"[[:alnum:]]+"
or_expressions(subexps, string \\ "", opts \\ []) View Source
Takes in a list of regex strings, and inserts an or operator between each of them.
Does not escape characters by default to preference OR-ing complex expressions and encourage composition.
Special character escaping is available via the escape: true
option.
Examples
iex> alias Verbalex, as: Vlx
iex> accepted_exprs = ["match", "any", "of", "these"]
iex> Vlx.or_expressions(accepted_exprs)
"(match|any|of|these)"
start_of_line(before \\ "") View Source
Express the start of a line regex anchor. Translates to '^'.
Examples
iex> alias Verbalex, as: Vlx
iex> Vlx.start_of_line() |> Vlx.find("A long time ago...") |> Regex.compile!()
~r/^(?:A\ long\ time\ ago\.\.\.)/
tab(before \\ "") View Source
Matches a tab character. Equivalent to "\t".
then(before, string, opts \\ []) View Source
Express a string literal to be matched exactly and wraps in a non-capturing group. Escapes special characters by default.
Turn off character escapes with the escape: false
option.
Examples
iex> alias Verbalex, as: Vlx
iex> Vlx.find("www.") |> Vlx.then("example.com")
"(?:www\\.)(?:example\\.com)"
whitespace(before \\ "") View Source
Matches a whitespace character - includes tabs and line breaks.
word(before \\ "") View Source
Matches a 'word', equivalent to [a-zA-Z0-9_]
word_boundary(before \\ "") View Source
Matches a 'word boundary' - a word bounary is the position between a word and non-word character (0-9A-Za-z_]
).
It is commonly thought of as matching the beginning or end of a string.
zero_or_more(before, string \\ "", opts \\ []) View Source
Express a pattern will occur zero or more times.
Examples
iex> alias Verbalex, as: Vlx
iex> "" |> Vlx.anything_in(string: "#@$%", class: :alnum) |> Vlx.zero_or_more()
"[#@$%[:alnum:]]*"