DEV Community

loading...

Discussion on: Daily Challenge #32 - Hide Phone Numbers

Collapse
brightone profile image
Oleksii Filonenko

Elixir:

defmodule Phone do
  def hide(string = <<plain::binary-size(5), hidden::binary>>) do
    String.match?(string, ~r/\d{3}-\d{3}-\d{4}/) &&
      plain <> String.replace(hidden, ~r/\d/, "X")
  end
end

Uses some bitstring pattern matching :)