I have the following replacement function
myString.replace(/\s\w(?=\s)/,"$1\xA0");
The goal is to take single-letter words (e.g. prepositions) and add inextricable space after them instead of the standard space.
However, the above variable $ 1 does not work for me. It inserts the text "$ 1" instead of part of the original matched string + nbsp.
What is the reason for the observed behavior? Is there any other way to achieve it?
javascript regex replace typography
Josef Richter
source share