I found myself wanting to do this in Elixir:
re_sentence_frag = %r/(\w([^\.]|\.(?!\s|$))*)(?=\.(\s|$))/
Regex.replace(re_sentence_frag, " oh. a DOG. woOf. ", String.capitalize("\\1"))
Of course, that has no effect. (It capitalizes the string "\\1"
just once.) What I really meant is to apply String.capitalize/1
to every match found by the replace
function. But the 3rd parameter can't take a function reference, so passing &(String.capitalize("\\1")
also doesn't work.
This seems so fundamental that I'm surprised it's not possible. Is there another approach that would as neatly express this kind of manipulation? It looks like the underlying Erlang libraries would not immediately support passing a function reference as the 3rd parameter, so this may not be completely trivial to fix in Elixir.
How would you program manipulation of each matched string?