The |> operator takes the result of the expression on its left and injects it as the first parameter of the function call to its right.
The Regex.replace function signature is this: run(regex, string, options \\ [])
The first argument is the regex.
Then how is it possible the following code to work without error iex(115)> "cats like catnip" |> String.replace(~r/cat/, "dog") "dogs like dognip" iex(116)>
In the last example it seems that the pipe operator injects the second argument of the function.
The typespec for Regex.replace/4 is replace(Regex.t, String.t, String.t | (... -> String.t), [term]) :: String.t, which has nothing to do with Regex.run/3.
The typespec for String.replace/4 is replace(String.t, pattern | Regex.t, String.t, keyword) :: String.t, and this is what you actually used in iex.