Elixir Exercism Acronym
I am working to understand xianrusso’s solution to Exercism’s Acronym solution.
defmodule Acronym do
def abbreviate(string) do
Regex.scan(~r/(?<![A-Z])[A-Z]|(?<!\')\b[a-z]/, string)
|> List.flatten
|> Enum.map(&String.upcase/1)
|> Enum.join
end
end
The portion that I am working to digest is the Regex.
I believe this link contains the answer I just want to confirm that what I am thinking is happening is indeed what is happening. Advanced Regex Tutorial—Regex Syntax
I believe that in this ~r/(?<![A-Z])[A-Z]/ - that the (?<![A-Z]) is saying that as long as where we are at in the string does not have a capital letter that immediately precedes it then we can continue to keep matching it to [A-Z].
I believe that in this ~r/(?<!’)\b[a-z]/ it is saying that as long as where we are at in the string there is not a ’ that precedes it then we can keep matching it to \b[a-z]