问题解决了!
我使用这个代码:
{
'begin': '\\/\\*'
'end': '\\*\\/'
'name': 'comment.block.documention.mylanguage'
},
这个正则表达式应该找到所有评论:
\/\*\n((.*?)\n)+\*\/
此正则表达式匹配所有多行注释,例如多行上的
/* ... */
,即使它们中包含 *
或 /
。
\/\*(([^\*]|\*(?!\/))*)\*\/
\/\*[\s\S\n]*?\*\/|\/\/.*$
// single line comments
/**
* multi
* line
* comments
* // including nested inline comments
* and without tripping on URL slashes (https://www.example.com)
*/
/* single line comments written using multi-line delimiters */
// /* single line comments written using MLDs and within a regular single line comment */
*
也很有用,这将选择注释之前的任何水平空白: *\/\*[\s\S\n]*?\*\/|\/\/.*$
will_select_this_area_as_well_together_with // the content of a deeply nested comment
当您必须对评论进行一些外部工作(例如翻译它们)时,这会很方便。通过复制空格,当您将注释粘贴回代码中时,您可以确保它们会滑回到原来的位置(按列)。
也就是说,为了避免错误并使该前缀更清晰,也应该可以将其写为
[[:space:]]*
,如下所示:
[[:space:]]*\/\*[\s\S\n]*?\*\/|\/\/.*$
但是 VS Code/Codium 似乎还不支持这种语法,所以我坚持使用
*
形式。