I don’t understand why the version below doesn’t work. It does the proper thing with the hyphenated words, but strips out sapces. I can fix it with Charlie’s space conversion/restoration process, but I don’t know why that’s necessary.
This is the code:
<$let
in="simple-words, some text, to-do"
pat=(\w)(\w*)(-+)(\w)(\w*)
rep="[[$1]uppercase[]addsuffix[$2]addsuffix[$3]] [[$4]uppercase[]addsuffix[$5]] +[join[]]"
>
This vanilla JS equivalent works just fine:
"simple-words, some text, to-do".replace(
/(\w)(\w*)(-+)(\w)(\w*)/gm,
(_, a, b, c, d, e) => a.toUpperCase() + b + c + d.toUpperCase() + e
) //=> "Simple-Words, some text, To-Do"
Can someone explain why spaces – not captured by the regex – are removed with this call to search-replace
?