Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.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查找所有组_Regex - Fatal编程技术网

Regex查找所有组

Regex查找所有组,regex,Regex,我想分析以下句子: 如果敏捷的棕色狗跳过懒惰的红色狗,那么疯狂的红色狗就会从懒惰的红色狗身边跑过去。 我想找到所有出现在“the”和“red dog”之间的字符。 当前正则表达式: .*the(.*?)red dog.* 预期结果组(请注意空格): “懒惰” “疯狂” “懒惰” 如何修改当前正则表达式以获得所有预期的组?尝试使用以下正则表达式 the(\s+\S+\s+)red dog 以下各项应起作用: \bthe\b((?:(?!\bthe\b).)*?)\bred dog\b 单词

我想分析以下句子:

如果敏捷的棕色狗跳过懒惰的红色狗,那么疯狂的红色狗就会从懒惰的红色狗身边跑过去。

我想找到所有出现在“the”和“red dog”之间的字符。 当前正则表达式:

.*the(.*?)red dog.*
预期结果组(请注意空格): “懒惰” “疯狂” “懒惰”

如何修改当前正则表达式以获得所有预期的组?

尝试使用以下正则表达式

the(\s+\S+\s+)red dog

以下各项应起作用:

\bthe\b((?:(?!\bthe\b).)*?)\bred dog\b
单词边界阻止您匹配像“then”而不是“The”这样的内容,
(.*)
已被替换为
((?:(?!\b.)*?)
,以确保在“红狗”附近没有“The”可以开始匹配


示例:

< P>编辑:考虑下面的正则表达式…

   (?<=the)\s?\w*?\s?(?=red dog)

(?对正则表达式使用什么语言/工具?我使用的是regex101,PHP,与questionfirst match
quick brown dog跳过lazy
中的链接相同。谢谢,这是最可重用的解决方案。我想包括在between@newuser根据此要求更新答案。请检查。第一个t匹配不是我想要的:快速的棕色狗跳过懒洋洋的回答。希望这有帮助。