简体   繁体   English

查找以撇号或双斜杠开头的代码注释的正则表达式模式是什么?

[英]What's the regex pattern for finding code comments starting with an apostrophe or a double slash?

I'm trying to write a language definition for prismjs that will highlight Xojo code. 我正在尝试为Arizonajs编写语言定义,以突出显示Xojo代码。

Comments in Xojo can be any of the following: Xojo中的注释可以是以下任意一项:

' A comment
// Another comment
rem A third comment

Comments can be inline, that is the following is valid: 注释可以是内联的,即以下内容有效:

dim a As Integer // still a comment

There are no multiline comments. 没有多行注释。

So far I have figured out how to highlight comments starting with the apostrophe using this regex pattern: 到目前为止,我已经弄清楚了如何使用此正则表达式模式突出显示以撇号开头的注释:

/'.*/

but I can't figure out the other two. 但我不知道另外两个。 Could anybody help? 有人可以帮忙吗?

Thanks, 谢谢,

这应该可以解决问题:

/('|\/\/|\brem\b).*/

Use a look behind: 看看后面:

/(?<=\/\/|'|\brem ).*/

See live demo . 观看现场演示

This matches the comment (not the delimiter). 这与注释 (而不是分隔符)匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM