1
1
defmodule Regex do
2
2
@moduledoc % S """
3
- Regular expressions for Elixir built on top of the re module
3
+ Regular expressions for Elixir built on top of the `re` module
4
4
in the Erlang Standard Library. More information can be found
5
- in the re documentation: http://www.erlang.org/doc/man/re.html
5
+ in the [`re` documentation]( http://www.erlang.org/doc/man/re.html).
6
6
7
- Regular expressions in Elixir can be created using Regex.compile!
7
+ Regular expressions in Elixir can be created using ` Regex.compile!`
8
8
or using the special form with `%r`:
9
9
10
10
# A simple regular expressions that matches foo anywhere in the string
@@ -13,10 +13,10 @@ defmodule Regex do
13
13
# A regular expression with case insensitive options and handling for unicode chars
14
14
%r/foo/iu
15
15
16
- The re module provides several options, the ones available in Elixir, followed by
16
+ The `re` module provides several options, the ones available in Elixir, followed by
17
17
their shortcut in parenthesis, are:
18
18
19
- * `unicode` (u) - enable unicode specific patterns like \p
19
+ * `unicode` (u) - enables unicode specific patterns like \p
20
20
* `caseless` (i) - add case insensitivity
21
21
* `dotall` (s) - causes dot to match newlines and also set newline to anycrlf.
22
22
The new line setting can be overridden by setting `(*CR)` or `(*LF)` or
@@ -27,8 +27,8 @@ defmodule Regex do
27
27
allow `#` to delimit comments
28
28
* `firstline` (f) - forces the unanchored pattern to match before or at the first
29
29
newline, though the matched text may continue over the newline
30
- * `ungreedy` (r) - invert the "greediness" of the regexp
31
- * `groups` (g) - compile with info about groups available
30
+ * `ungreedy` (r) - inverts the "greediness" of the regexp
31
+ * `groups` (g) - compiles with info about groups available
32
32
33
33
The options not available are:
34
34
@@ -53,10 +53,18 @@ defmodule Regex do
53
53
54
54
The given options can either be a binary with the characters
55
55
representing the same regex options given to the `%r` sigil,
56
- or a list of options, as expected by the Erlang `re` docs.
56
+ or a list of options, as expected by the [ Erlang `re` docs](http://www.erlang.org/doc/man/re.html) .
57
57
58
58
It returns `{ :ok, regex }` in case of success,
59
59
`{ :error, reason }` otherwise.
60
+
61
+ ## Examples
62
+
63
+ iex> Regex.compile("foo")
64
+ {:ok, %r"foo"}
65
+ iex> Regex.compile("*foo")
66
+ {:error, {'nothing to repeat', 0}}
67
+
60
68
"""
61
69
@spec compile( binary, binary | [ term ] ) :: t
62
70
def compile ( source , options // "" )
@@ -256,7 +264,7 @@ defmodule Regex do
256
264
end
257
265
258
266
@ doc """
259
- Split the given target into the number of parts specified.
267
+ Splits the given target into the number of parts specified.
260
268
If no number of parts is given, it defaults to `:infinity`.
261
269
262
270
## Examples
0 commit comments