Weird regex behavior on a simple mode


Hi all,

I’m trying to create a mode that allows Todo.txt format which is very very simple but having a weird regex behavior when codemirror is matching results.

Basically I’m trying to mark all lines starts with “x” following a space character and having this condition only at the beginning of a line but regex picks up a string in the middle of the line.

My regex doesn’t match this condition when trying on other javascript regex tools:

Here is my regex line from the simple mode definition:
{regex: /^(x ).*$/, token: “task-completed”},

And the text I’m testing against:
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
© @geek add priority shortcut cmd+up/down or similar +todotxtapp
asdasdasdasdasa x dsljhdsfkljg dhsklf sdaf

In practice it only needs to match the first line. But it matches the half part of second line and the last line.
See result here:


stream.match will match the regexp against the remainder of the line, starting from the current position. You need stream.sol() to check whether that position is at the start of a line.



didn’t know how to do it on the simple mode but after reading source for the simple mode, adding sol:true to my rule made it work.