查找“//”后面除了空格之外的任何符号

时间:2023-02-03 03:34:48

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 "//$..."

但是这与字符串不匹配,例如“//$…”

1 个解决方案

#1


3  

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)

#1


3  

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)