I am just a bit concerned about this method of computing the number of matches. It's quite hard to verify. I am not completely sure that the regexp above escapes anything that can possible appear in a regexp. Also, CodeMirror uses `indexOf` to find matches and it might behave differently from `string.match`. How about we do it more directly, by scanning the string with `indexOf`?

One extra thing worth checking is that we handle overlapping matches the same way as SearchCursor. Simple example: how many matches are there for "aa" in the string "aaa"?