ACE Editor多行正则表达式 [英] ACE Editor multiline regex

查看:249
本文介绍了ACE Editor多行正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ACE Editor来突出显示我网站的BBCode系统的语法,并且总体来说运行良好。唯一不是我们的等效项是多行注释:

  [nobbcode] 
我是一个演示[b] BBCode [/ b]。
此处的所有内容均显示为纯文本,并保留完整的代码,
允许人们展示其工作方式。
[/ nobbcode]

此规则是:

  {
令牌:[
meta.tag.punctuation.tag-open.xml,
meta。 tag.tag-name.xml,
meta.tag.punctuation.tag-close.xml,
评论,
meta.tag.punctuation.end-tag- open.xml,
meta.tag.tag-name.xml,
meta.tag.punctuation.tag-close.xml
],
正则表达式: /(\ [](nobbcode)(\])([\s\S] *?)(\ [\ /](nobbcode)(\])/,
不区分大小写:真
},

在这样的示例中,效果很好:

 您可以使用[nobbcode] [b] ... [/ b] [/ nobbcode]来指定粗体文本。 

其中的匹配项位于单行中,但似乎不喜欢多行文本。 / p>

ACE不支持多行正则表达式,如果可以,我应该将其分解为开始注释,注释,结束注释部分吗?

解决方案

由于@Thomas的评论,我了解到ACE逐行分析,因此多行正则表达式将无法工作。



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

  {
令牌:[
meta.tag.punctuation.tag-open.xml,
meta.tag.tag-name.xml,
meta.tag.punctuation.tag-close- .xml
],
正则表达式:/(\ [](nobbcode)(\])/,
caseInsensitive:true,
push:[
{
令牌:[
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}
]
},

向下到开始-中间-末端,使用 defaultToken 将注释令牌应用于中间部分。



I只是希望ACE有更好的记录...


I'm using ACE Editor to syntax highlight my website's BBCode system, and on the whole it's working well. The only thing that isn't is our equivalent to multiline comments:

[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]

The rule for this is:

{
    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
},

And it works great in an example like this:

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

where the match is on a single line, but it doesn't seem to like multiline text.

Does ACE not support multi-line regex, and if so should I instead break it down into "start comment, comment, end comment" parts?

解决方案

Thanks to @Thomas' comment, I learned that ACE parses line-by-line, and therefore multiline regexes will not work.

I fixed my issue with the following syntax rule:

{
    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"}
    ]
},

This essentially breaks it down into start-middle-end, applying the "comment" token to the middle part with defaultToken.

I just wish ACE were documented better...

这篇关于ACE Editor多行正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆