Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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/3/sockets/2.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,我不想把两个角色之间的所有东西都匹配起来,就像在。我在寻找一个特定的短语。例如: cat {mouse ostrich dog ostrich} fish {ostrich} ostrich 我想匹配花括号中的三根“鸵鸟”弦,但不想匹配其他任何东西。这可能吗?如果您的引擎支持\G(PCRE…),您可以很好地与 (?:\G(?!\A)|{) # match the start of the last match or { [^{}]*?\K # not { or } lazily, \

我不想把两个角色之间的所有东西都匹配起来,就像在。我在寻找一个特定的短语。例如:

cat {mouse ostrich dog ostrich} fish {ostrich} ostrich

我想匹配花括号中的三根“鸵鸟”弦,但不想匹配其他任何东西。这可能吗?

如果您的引擎支持
\G
(PCRE…),您可以很好地与

(?:\G(?!\A)|{) # match the start of the last match or {
[^{}]*?\K      # not { or } lazily, \K "forgets" the match thus far
ostrich        # ostrich literally

请参阅。

请说明您迄今为止所做的工作以及失败的地方。