Skip to content

Commit caeea89

Browse files
committed
Support extended syntax in Regex.escape
1 parent 6656f7c commit caeea89

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/elixir/lib/regex.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ defmodule Regex do
291291
:re.replace(string, compiled, replacement, opts)
292292
end
293293

294-
{ :ok, pattern } = :re.compile(%B"[.^$*+?()[{\\\\|]")
294+
{ :ok, pattern } = :re.compile(%B"[.^$*+?()[{\\\|\s#]", [:unicode])
295295
@escape_pattern pattern
296296

297297
@spec escape(String.t | char_list) :: String.t | char_list

lib/elixir/test/elixir/regex_test.exs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,15 @@ defmodule Regex.BinaryTest do
143143
assert escaping("(", "(")
144144
assert escaping("()", "()")
145145
assert escaping("(?:foo)", "(?:foo)")
146+
147+
assert escaping("\\A \\z", "\\A \\z")
148+
assert escaping(" x ", " x ")
149+
assert escaping("  x    x ", "  x    x ") # unicode spaces here
150+
assert escaping("# lol", "# lol")
146151
end
147152

148153
defp escaping(string, match) do
149-
Regex.match? %r/#{Regex.escape(string)}/, match
154+
Regex.match? %r/#{Regex.escape(string)}/xu, match
150155
end
151156
end
152157

0 commit comments

Comments
 (0)