Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 正则表达式:在所选文本前面包含3个单词,后面包含3个单词_Regex_Text_Google Sheets - Fatal编程技术网

Regex 正则表达式:在所选文本前面包含3个单词,后面包含3个单词

Regex 正则表达式:在所选文本前面包含3个单词,后面包含3个单词,regex,text,google-sheets,Regex,Text,Google Sheets,Im在excel中使用此正则表达式代码在段落中查找所需文本: =RegexExtract(B2,"(bot|vehicle|scrape)") 这段代码将成功返回段落中的所有3个单词,我想做的额外工作是让正则表达式返回所需的粗体文本,以及所选单词前面的几个单词和后面的3个单词 文本示例: A car (or automobile) is a wheeled motor vehicle used for transportation. Most definitions of car say t

Im在excel中使用此正则表达式代码在段落中查找所需文本:

=RegexExtract(B2,"(bot|vehicle|scrape)")
这段代码将成功返回段落中的所有3个单词,我想做的额外工作是让正则表达式返回所需的粗体文本,以及所选单词前面的几个单词和后面的3个单词

文本示例:

A car (or automobile) is a wheeled motor vehicle used for transportation. 
Most definitions of car say they run primarily on roads, seat one to eight people,
have four tires, and mainly transport people rather than goods.
示例输出:

a wheeled motor **vehicle** used for transportation
我希望文本的一部分出现,以便接收者能够更容易地确定文本的位置

非常感谢任何替代方法。

您可以使用

=RegexExtract(B2,"(?:\w+\W+(?:\w+\W+){0,2})?(?:bot|vehicle|scrape)(?:\W+\w+(?:\W+\w+){0,2})?")
请参阅和:

详细信息:该模式用捕获括号括起来,以使
REGEXEXTRACT
实际提取满足以下模式的所需字符串:

  • (?:\w+\w+(?:\w+\w+{0,2})
    -一个单词的可选序列,后跟非单词字符,后跟零,一个或两个重复的1+单词字符,然后是1+非单词字符
  • (?:bot | vehicle | scrape)
    -a
    bot
    vehicle
    scrape
    word
  • (?:\W+\W+(?:\W+\W+{0,2})
    -一个可选的序列,由1+非单词字符和1+单词字符组成,然后是零、一个或两个重复的1+非单词字符和1+单词字符
谷歌电子表格测试:


尝试
((?:\w+(?:\w+\w+{0,2})\w+(?:bot | vehicle | scrape)(?:\w+\w+(?:\w+\w+{0,2})”
,请参阅。@WiktorStribiżew Regex101似乎找到了匹配项,但excel返回一个空白单元格,没有错误。请参阅@WiktorStribiżew aware,工作得很好!谢谢你的帮助!把它贴在下面作为答案,它值得投票@JohnCould我想这就是全部:注意
\w+
\w+
在术语前后是如何交替的。它们应该交错。