【发布时间】:2017-12-13 01:21:51
【问题描述】:
我正在尝试创建一个允许 Todo.txt 格式的模式,该格式非常简单,但在 codemirror 匹配结果时会出现奇怪的正则表达式行为。
基本上,我试图标记所有行以空格字符后的“x”开头,并且仅在行首具有此条件,但正则表达式会在行中间选择一个字符串。
在尝试使用其他 javascript 正则表达式工具时,我的正则表达式与此条件不匹配:https://regex101.com/r/kUXTqf/1
这是我的简单模式定义中的正则表达式行:
{regex: /^(x ).*$/, token: "task-completed"}
以及我正在测试的文本:
x 2017-12-12 @geek add file location preference option +todotxtapp
(A) @geek completed task syntax highlighter rule needs tweak - it includes any character follows with whitespace - starting in the middle of the line +todotxtapp
(B) @geek design new app icon +todotxtapp
(C) @geek add priority shortcut cmd+up/down or similar +todotxtapp
asdasdasdasdasa x dsljhdsfkljg dhsklf sdaf
实际上,它只需要匹配第一行。但它匹配第二行和最后一行的一半。 在此处查看结果:http://take.ms/S2PEL
【问题讨论】:
-
奇怪,我找不到讨论这种行为的文档。正如您的工作 Regex101 演示所示,我希望您的模式能够按照您的想法工作。
标签: javascript regex codemirror