Skip to content

Commit c6ff84e

Browse files
author
José Valim
committed
Improve docs and exceptions for regexes
1 parent 0e47d8c commit c6ff84e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/elixir/lib/regex.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ defmodule Regex do
127127

128128
captures =
129129
case Keyword.get(options, :capture, :all) do
130-
:groups -> groups || raise "regex was not compiled with g"
130+
:groups -> groups || raise ArgumentError, message: "regex was not compiled with g"
131131
others -> others
132132
end
133133

@@ -139,6 +139,7 @@ defmodule Regex do
139139

140140
@doc """
141141
Returns the given captures as a list of tuples.
142+
Requires the regex to be compiled with the groups option.
142143
143144
## Examples
144145
@@ -150,7 +151,7 @@ defmodule Regex do
150151
captures = if groups do
151152
Enum.sort(groups)
152153
else
153-
raise "Regex was not compiled with g"
154+
raise ArgumentError, message: "regex was not compiled with g"
154155
end
155156
options = Keyword.put(options, :capture, captures)
156157
end
@@ -159,7 +160,7 @@ defmodule Regex do
159160
end
160161

161162
@doc """
162-
Returns the underlying re_pattern in the regular expression.
163+
Returns the underlying `re_pattern` in the regular expression.
163164
"""
164165
def re_pattern(regex(re_pattern: compiled)) do
165166
compiled

0 commit comments

Comments
 (0)