Skip to content

Commit 3dd445b

Browse files
committed
Add documentation to Regex.escape
1 parent 5e80348 commit 3dd445b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/elixir/lib/regex.ex

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,17 @@ defmodule Regex do
294294
{ :ok, pattern } = :re.compile(%B"[.^$*+?()[{\\\|\s#]", [:unicode])
295295
@escape_pattern pattern
296296

297+
@doc %B"""
298+
Escapes a string to be literally matched in a regex.
299+
300+
## Examples
301+
302+
iex> Regex.escape(".")
303+
"\\."
304+
iex> Regex.escape("\\what if")
305+
"\\\\what\\ if"
306+
307+
"""
297308
@spec escape(String.t | char_list) :: String.t | char_list
298309
def escape(string) do
299310
:re.replace(string, @escape_pattern, "\\\\&", [:global, { :return, return_for(string) }])

0 commit comments

Comments
 (0)