我希望将选择范围扩展到整个句子。但我无法设法产生正确的正则表达式。到目前为止,这是我的代码:
var re_string = "[.?!](.*?"+RegExp.quote(selector)+".*?[.?!])"
var re = new RegExp(re_string, "g");
var str = jQuery(wpccparams.selectors).text();
var m;
while ((m = re.exec(str)) !== null) {
if (m.index === re.lastIndex) {
re.lastIndex++;
}
console.log(m)
}
示例:
选择
"urn value to the sc" // [.?!](.*?urn value to the sc.*?[.?!])
应该给我
“不幸的是,它还回显了屏幕的返回值,并且无法将其实际返回到最初调用过滤器的函数。”
在本文中:
“。似乎$ post只适用于在某些时间执行的钩子。我有一个”init“钩子需要使用$ post-> ID从数据库中提取一些数据。所以我唯一的解决方法已经在the_content上添加了另一个过滤器,它使用$ post来获取我需要的信息。不幸的是,它还回显了屏幕的返回值,并且无法将其实际返回到最初调用过滤器的函数。这是提取我需要的数据的代码,但回显并且无法返回值:“
不工作示例:https://regex101.com/r/eS5jD9/2
也应该可以选择两个句子。
答案 0 :(得分:2)
[.?!]([^.?!]*?urn value to the sc.*?[.?!])
使用此功能。.*?
不应与其他.?!
匹配。请使用negated quantifier
。请参阅演示。