ACE编辑器多行正则表达式

时间:2016-02-09 10:01:40

标签: javascript regex ace-editor

我使用ACE编辑器突出显示我网站的BBCode系统,并且整体上运行良好。唯一不是我们相当于多行注释:

[nobbcode]
    I am a demo of [b]BBCode[/b].
    Anything in here is shown as plain text, with code left intact,
    allowing people to show how it works.
[/nobbcode]

这个规则是:

{
    token:[
        "meta.tag.punctuation.tag-open.xml",
        "meta.tag.tag-name.xml",
        "meta.tag.punctuation.tag-close.xml",
        "comment",
        "meta.tag.punctuation.end-tag-open.xml",
        "meta.tag.tag-name.xml",
        "meta.tag.punctuation.tag-close.xml"
    ],
    regex:/(\[)(nobbcode)(\])([\s\S]*?)(\[\/)(nobbcode)(\])/,
    caseInsensitive:true
},

它在这样的例子中效果很好:

You can use [nobbcode][b]...[/b][/nobbcode] to designate bold text.

匹配在一行上,但它似乎不喜欢多行文字。

ACE不支持多行正则表达式,如果是这样,我应该将其分解为"开始评论,评论,结束评论"份?

1 个答案:

答案 0 :(得分:0)

感谢@Thomas的评论,我了解到ACE逐行解析,因此多行正则表达式无效。

我使用以下语法规则解决了我的问题:

gulpfile.js

这实际上将其分解为start-middle-end,将“comment”标记应用于{ token:[ "meta.tag.punctuation.tag-open.xml", "meta.tag.tag-name.xml", "meta.tag.punctuation.tag-close.xml" ], regex:/(\[)(nobbcode)(\])/, caseInsensitive:true, push:[ { token:[ "meta.tag.punctuation.end-tag-open.xml", "meta.tag.tag-name.xml", "meta.tag.punctuation.tag-close.xml" ], regex:/(\[\/)(nobbcode)(\])/, caseInsensitive:true, next:"pop" }, {defaultToken:"comment"} ] }, 的中间部分。

我希望ACE更好地记录下来......