Tautvydas Tautvydas - 1 year ago 140
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 Source

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:


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


which will possibly impress your colleagues more.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download