从仅包含URL字符串中的特定单词的文本中获取图像URL

问题描述:

I use preg_match_all to get all images URLs from the text string:

preg_match_all('!http://[^?#]+\.(?:jpe?g|png|gif)!Ui', $text , $matches);
  • Unfortunately, this time I need to get only images that contains '/bigimage/' inside the initial string.

  • i.e. $matches array should have only contains image elements like:

  http://x/x/bigimage/x/x.jpg
  • How could I modify source command to get desired result?

我使用preg_match_all从文本字符串中获取所有图像URL: p>

   preg_match_all('!http:// [^?#] + \。(?:jpe?g | png | gif)!Ui',$ text,$ matches); 
  code>  pre  > 
 
 
  • 不幸的是,这次我只需要在初始字符串中只包含'/ bigimage /'的图像。 p> li>

  • ie $ matches数组应该只包含图像元素,如: p> li> ul>

      http:/  /x/x/bigimage/x/x.jpg
    
    nn
    • 我如何修改源命令以获得所需的结果 ? li> ul> div>

try

(http://(?:\w+/)*bigimage(?:/\w+)*((/\w).(?:jpe?g|png|gif)))

for visualization https://www.debuggex.com/r/22db9byd3cTlIX6f

Change the brackets () or capturing groups according to your need