如何在ACE编辑器中突出显示每行中的第一个单词? [英] How to highlight the first word in each line in ACE editor?

查看:88
本文介绍了如何在ACE编辑器中突出显示每行中的第一个单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有这样的代码:

ab cd
ef gh
  ij kl
mn

我想突出显示行头的所有单词: ab ef ij (是的,我们有缩进) mn ,如何写正则表达式:

I want to highlight all words at line head: ab ef ij (yes, we have indentations) mn, how to write the regex:?

我试过 http://ace.c9.io/tool/mode_creator.html / ^ \ * * / \ n / 未按预期工作。实际上它们是如何工作的?

I had a try at http://ace.c9.io/tool/mode_creator.html but /^\s*/ /\n/ was not working as expected. How actually do they work?

推荐答案

Ace连接组中规则中的所有正则表达式。
所以如果你有一个像

Ace concatenates all the regular expressions in rules in a group. So if you have a group like

[{token:..,regex:regex1},{token :. 。,regex:/ regex2 /},{defaultToken:..}]

结果正则表达式为 / (regex1)(regex2)($)/ (参见这里
文档中的每一行都会重复匹配生成的正则表达式,并且每个匹配标记都会创建相应规则的类型。对于不匹配的文本,使用defaultToken。

Resulting regular expression will be /(regex1)(regex2)($)/ (see here) Every line in document is repeatedly matched to the resulting regex and for each match token with the type of corresponding rule is created. For unmatched text defaultToken is used.

因为正则表达式在规则中逐行匹配 / \ n / 不会匹配任何东西。

Since regular expressions are matched line by line /\n/ in rules will not match anything.

关于你的第一个问题,我认为 {token:comment,regex:^ \\ * * \\\\ + +}} 应该有效。

As for your first question I think {token : "comment", regex : "^\\s*\\w+"} should work.

这篇关于如何在ACE编辑器中突出显示每行中的第一个单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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