search

Home  >  Q&A  >  body text

java - 正则表达式匹配多次出现的内容,并且提取

我想提取html中的img的src中的内容,匹配是否有img,如果有全部的src都提取出来,请大神赐教。(用java处理)

这个是测试图片1<img src="file:///storage/emulated/0/DCIM/Screenshots/Screenshot_hahaha.png" alt="">
这个是测试图片2<img src="file:///storage/emulated/0/DCIM/Screenshots/Screenshot_lalala.png" alt="">

巴扎黑巴扎黑2803 days ago710

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-04-18 10:53:26

    regular expression to implement, of course I use phplanguage to implement

    $body = '<img src="file:///storage/emulated/0/DCIM/Screenshots/Screenshot_hahaha.png" alt=""><img src="file:///storage/emulated/0/DCIM/Screenshots/Screenshot_lalala.png" alt="">';
    $imgreg = "/<img src=\"(.*?)\"/";
    if(preg_match_all($imgreg, $body, $matches)){
        var_dump($matches[1]);
    }

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:53:26

    Convert the code above into js

    var body = '<img src="file:///storage/emulated/0/DCIM/Screenshots/Screenshot_hahaha.png" alt=""><img src="file:///storage/emulated/0/DCIM/Screenshots/Screenshot_lalala.png" alt="">'
    
    var sources = []
    var imgReg = /<img src=\"(.*?)\"/g
    var match
    while((match = imgReg.exec(body))){
        sources.push(match[1])
    }
    console.log(sources)

    reply
    0
  • Cancelreply