Regex 使用包含“的单词序列编写正则表达式”;或;

Regex 使用包含“的单词序列编写正则表达式”;或;,regex,Regex,我想提取与或“相关的单词序列。例如,从 "there or is or a or problem with my computer" 我想提取 "there or is or a or problem" 我有下面的正则表达式 (("[^"]+"+|.[^\s*]+)\s+or\s+)+("[^"]+"+|.[^\s*]+) 但该表达式给出了以下结果: "there or is", " a or problem or with" 在单个字符处中断。表达式有问题吗?连接的是字母拼写的单词,

我想提取与
或“
相关的单词序列。例如,从

 "there or is or a or problem with my computer"
我想提取

"there or is or a or problem"
我有下面的正则表达式

(("[^"]+"+|.[^\s*]+)\s+or\s+)+("[^"]+"+|.[^\s*]+)
但该表达式给出了以下结果:

"there or is", " a or problem or with"

在单个字符处中断。表达式有问题吗?

连接的是字母拼写的单词,可能是:

\w+(?:\s+or\s+\w+)*
这会回来的

"there or is or a or problem",  "with", "my", "computer"
"there or is or a or problem"
如果您真的只想要其中至少有一个
的,如您的示例所示

\w+(?:\s+or\s+\w+)+
会回来的

"there or is or a or problem",  "with", "my", "computer"
"there or is or a or problem"
请尝试以下方法:

[\w\s]+or\s+\w+
注意,这将与以下突出显示的匹配:

我的电脑有问题,我快疯了

但是,如果您想有或有或有问题计算机或i,请选择:

(\w+(?:\s+or\s+\w+)+)

这是什么课?我们在一两天前刚刚遇到过这个问题,出于同样的原因,建议的解决方案仍然是错误的。我们将其用于全文搜索逻辑。我将其更改为((“[^”]+“+”+)?[^\s*]+)\s+或\s+(“[^”]+“+?[^\s*])?之后这一切都如期而至