Regex 匹配句子的Javascript正则表达式

Regex 匹配句子的Javascript正则表达式,regex,Regex,我有以下示例段落: 以下是我的文本。我的介绍行是这个,那个和其他。我的第二行和以前差不多,但完全不同。不要谈论我的第三行文字。 我想用正则表达式捕捉以下句子: 我的介绍行是这个,那个和其他。 因此,我的守则是: (\bMy\sintroductory\sline\sof\stext).*(\.) (\bMy\sinProductory\sline\sof\stext)。*(\) 但是这会得到所有的文本。我怎样才能捕捉到第一个句号 (\bMy\sintroductory\sline\sof\ste

我有以下示例段落:

以下是我的文本。我的介绍行是这个,那个和其他。我的第二行和以前差不多,但完全不同。不要谈论我的第三行文字。 我想用正则表达式捕捉以下句子:

我的介绍行是这个,那个和其他。 因此,我的守则是:

(\bMy\sintroductory\sline\sof\stext).*(\.) (\bMy\sinProductory\sline\sof\stext)。*(\) 但是这会得到所有的文本。我怎样才能捕捉到第一个句号

(\bMy\sintroductory\sline\sof\stext).*?\.
这将使
*
取消冻结,并且它将匹配尽可能少的字符。

请注意区别:

(\bMy\sintroductory\sline\sof\stext)[^\.]*\.

这里有一些用于我的方法和Piskvor的基准测试代码

角色类方法:通过Firefox在我的机器上运行约550ms

var start = (new Date()).getTime();
for(var i=0;i<100000;i++){
"The following is my text. My introductory line of text is the this, that and the other. My second line is much the same as before but completely different. Don't even talk about my third line of text.".match(/(\bMy\sintroductory\sline\sof\stext)[^\.]*\./);
}
var stop = (new Date()).getTime();
alert(stop - start);
var start = (new Date()).getTime();
for(var i=0;i<100000;i++){
"The following is my text. My introductory line of text is the this, that and the other. My second line is much the same as before but completely different. Don't even talk about my third line of text.".match(/(\bMy\sintroductory\sline\sof\stext).*?\./);
}
var stop = (new Date()).getTime();
alert(stop - start);
var start=(新日期()).getTime();

对于(var i=0;iIt)来说,找出哪种方法更快会很有意思。@Alin Purcaru:我会考虑你的方法,因为它只对当前角色感兴趣。我看到你的基准测试似乎证实了这一点。我得到了与你相似的结果。字符类方法似乎稍微快一点。感谢这两个完整的答案!非常感谢