Javascript 如何在Codemirror中正则表达式以匹配段落开头和结尾的单词?

Javascript 如何在Codemirror中正则表达式以匹配段落开头和结尾的单词?,javascript,regex,codemirror,codemirror-modes,Javascript,Regex,Codemirror,Codemirror Modes,我正在使用Codemirror构建一个文本编辑器,它有一些很好的功能,比如语法高亮显示,在中使用语言模式,并尝试编写几个正则表达式来匹配段落的第一个和最后一个单词。例如,在: One is the first one of all the numbers Two is the second 第一个正则表达式(段落中的第一个单词)应该匹配One和Two,第二个正则表达式(段落中的最后一个单词)应该匹配number和second 我一直在尝试不同的表达方式,但最终找不到正确的表达方式。这是我得到

我正在使用Codemirror构建一个文本编辑器,它有一些很好的功能,比如语法高亮显示,在中使用语言模式,并尝试编写几个正则表达式来匹配段落的第一个和最后一个单词。例如,在:

One
is the first one
of all the numbers

Two is
the second
第一个正则表达式(段落中的第一个单词)应该匹配
One
Two
,第二个正则表达式(段落中的最后一个单词)应该匹配
number
second

我一直在尝试不同的表达方式,但最终找不到正确的表达方式。这是我得到的最接近的结果,但显然仍然不对:

/[^\r\n]+[a-zA-Z]\s/
谁能给我指一下正确的方向吗?
提前感谢。

使用记事本++和rubular.com进行测试

查找内容:
^[A-Z]\w+(\s\w+)(\r?\n\r)([A-Z]+\s)++(\w+)$

替换为:
\1\n\6

输入

One
is the first one
of all the numbers

Two is
the second

Three is
the third

Four is
the fourth
of all the numbers
One
numbers

Two
second

Three
third

Four
numbers
输出

One
is the first one
of all the numbers

Two is
the second

Three is
the third

Four is
the fourth
of all the numbers
One
numbers

Two
second

Three
third

Four
numbers
红肿的


我知道这个问题已经存在了一段时间,但我想与大家分享一下,对于CodeMirror正则表达式,通常的“^”不能用于行/字符串匹配的开头。但是,{regex:…,sol:true}工作正常。 例如,定义为简单模式()
“sol”代表“行的开始”

此正则表达式在Codemirror中不起作用。请注意,这个问题是针对CodeMirror的,而不是一般的正则表达式。