diff options
author | Christopher Eyre <chriseyre2000@gmail.com> | 2019-02-10 08:29:35 +0000 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2019-02-10 09:29:35 +0100 |
commit | e80b06574c454f3c54b92535757657d2e162edca (patch) | |
tree | d934c4eb827fce5d576f7e4db3d3634b227c3b6d | |
parent | 352dd7f78c5aeb982863929c2290349e6b820857 (diff) | |
download | elixir-e80b06574c454f3c54b92535757657d2e162edca.tar.gz |
Added regex documentation for named character classes (#8785)
-rw-r--r-- | lib/elixir/lib/regex.ex | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/elixir/lib/regex.ex b/lib/elixir/lib/regex.ex index 6b9310266..30fa05235 100644 --- a/lib/elixir/lib/regex.ex +++ b/lib/elixir/lib/regex.ex @@ -103,6 +103,41 @@ defmodule Regex do * `list(binary)` - a list of named captures to capture + ## Character classes + + Regex supports several built in named character classes. These are used by + enclosing the class name in `[: :]` inside a group. For example: + + iex> String.match?("123", ~r/^[[:alnum:]]+$/) + true + iex> String.match?("123 456", ~r/^[[:alnum:][:blank:]]+$/) + true + + The supported class names 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 + + Note the behaviour of those classes may change according to the Unicode + and other modifiers: + + iex> String.match?("josé", ~r/^[[:lower:]]+$/) + false + iex> String.match?("josé", ~r/^[[:lower:]]+$/u) + true + """ defstruct re_pattern: nil, source: "", opts: "", re_version: "" |