Replace a space via regex?


I am trying to replace text with spaces so that no spaces remain.

Here is the sample text:

 Content: “blah blah blah.”

The following script produces the following output

const findRegex = /\sContent:\s/g;
const replaceWith = "";

draft.content = draft.content.replace(findRegex, replaceWith);


 “blah blah blah.”

Is there a way to produce output that does not start with a space? I thought the two ‘\s’ flags in the regex would do that.


That should remove the space between Content: and ”blah” but only finds the first space prior to Content: - if you want to find all spaces leading up to it, add a + qualifier, like:


(You might want it on the \s after, too, if there could be more than one space to strip there, too)


Well, that pattern deleted all the text on the line. This works though:

/\ \ Content:\s/g

Thanks for the hint! I forgot there were two spaces there