dsebywql016137 2018-07-27 18:59
浏览 20

正则表达式不断改变

I have this content and i want to extract the part of src: 1080. The thing is the src part comes before the 1080 and there are more than than 1 1080 src part. I want to extact all the src of config_width":1080 with regex. How can i do it? i tried it with get string between but it doesnt work as the 750 width part keeps on changing occasionally. only constant is config_width":1080

n.jpg","config_width":640,"config_height":640},{"src":"https://instagram.fbom11-1.fna.fbcdn.net/vp/4ccd16cba349973a390bc41275ad115e/5BF3C2A8/t51.2885-15/sh0.08/e35/s750x750/37256801_203159180380375_5976119398048464896_n.jpg","config_width":750,"config_height":750},{"src":"https://instagram.fbom11-1.fna.fbcdn.net/vp/16f84975e497c784cbfede0a85a3aac0/5BEF904D/t51.2885-15/e35/37256801_203159180380375_5976119398048464896_n.jpg","config_width":1080,"config_height":1080}],

Code I tried:

function get_string_between($string, $start, $end){
    $string = " ".$string;
    $ini = strpos($string,$start);
    if ($ini == 0) return "";
    $ini += strlen($start);   
    $len = strpos($string,$end,$ini) - $ini;
    return substr($string,$ini,$len); 
}
  • 写回答

1条回答 默认 最新

  • doushijia5684 2018-07-27 19:13
    关注

    You could use a lookahead to do a simple check for the 1080 part after you've matched the src part (the url will be in the match result named group "src"):

    src":"(?<src>[^"]+)",(?="config_width":1080)
    

    regex101 demo

    评论

报告相同问题?

悬赏问题

  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答