I want to surround all "E" words in string by spaces using regexp, e.g.
'E+Error+E+E+LATTE+E' -> ' E +Error+ E + E +LATTE+ E '
My unsuccessful attempt:
node> 'E+Error+E+E+LATTE+E'.replace(new RegExp(`(^|\\W)(E)(\\W|$)`, 'gi'), '$1 $2 $3')
' E +Error+ E +E+LATTE+ E '
^^^ - no spaces
Or ever simple:
nesh> 'E+E+E+E+E'.replace(new RegExp(`(^|\\W)(E)(\\W|$)`, 'gi'), '$1 $2 $3')
' E +E+ E +E+ E '
Can the regex be used for a task like this?