VS Code正则表达式匹配空白,包括换行符?

huangapple go评论51阅读模式
英文:

VS Code regular expression white space including newlines?

问题

尝试匹配包括换行符的空白,然后是大括号{},然后将匹配的空白合并为单个空格

匹配\s*([{}])不包括前面的换行符:

VS Code正则表达式匹配空白,包括换行符?

因此,替换 $1 不会合并换行符:

VS Code正则表达式匹配空白,包括换行符?

英文:

Attempting to match white space including newlines followed by a brace, { or } then collapse the matching white space to a single space, .

Matches \s*([{}]) do not include the preceding newlines:

VS Code正则表达式匹配空白,包括换行符?

So, the replacement $1 does not collapse the newlines:

VS Code正则表达式匹配空白,包括换行符?

答案1

得分: 1

你可以使用:

[\s*\n*]*([{}])

\n 代表换行

生成:

VS Code正则表达式匹配空白,包括换行符?

英文:

You can use:

[\s*\n*]*([{}])

\n for newline

Produces:

VS Code正则表达式匹配空白,包括换行符?

huangapple
  • 本文由 发表于 2023年6月1日 00:53:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76375764.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定