Skip to content

Commit 4315fc8

Browse files
committed
Add examples using alternate capture/replace syntax
1 parent 73b64cb commit 4315fc8

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/elixir/lib/regex.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,9 @@ defmodule Regex do
456456
iex> Regex.replace(~r/a(b|d)c/, "abcadc", "[\\1]")
457457
"[b][d]"
458458
459+
iex> Regex.replace(~r/\.(\d)$/, "500.5", ".\\g{1}0")
460+
"500.50"
461+
459462
iex> Regex.replace(~r/a(b|d)c/, "abcadc", fn _, x -> "[#{x}]" end)
460463
"[b][d]"
461464

lib/elixir/lib/string.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ defmodule String do
703703
`\g{N}` in the `replacement` string to access a specific capture in the
704704
regex:
705705
706-
iex> String.replace("a,b,c", ~r/,(.)/, ",\\1\\1")
706+
iex> String.replace("a,b,c", ~r/,(.)/, ",\\1\\g{1}")
707707
"a,bb,cc"
708708
709709
Notice we had to escape the escape character `\`. By giving `\0`,

0 commit comments

Comments
 (0)