Tautvydas Tautvydas - 3 months ago 9
Javascript Question

RegExp: find "//" followed by any symbol except space

Title says it all. My intention is to insert a space by replacing the match with

"// "
.

So far I tried this:

\/\/\b(?! )


But this does not match strings such as
"//$..."

Answer

Use a negative look ahead for a space:

\/\/(?! )

Although this answers your question as stated, I suspect you actually don't want to match when // is at the end of a line (which would qualify under your question's definition). If so, use a positive look ahead for a non whitespace char:

\/\/(?=\S)

Or alternatively, use \B to match a non-word boundary:

\/\/\B

which will possibly impress your colleagues more.