cari

Rumah  >  Soal Jawab  >  teks badan

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 hari yang lalu712

membalas semua(2)saya akan balas

  • 大家讲道理

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

    Ungkapan biasa untuk dilaksanakan, sudah tentu saya menggunakan php bahasa untuk melaksanakan

    $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]);
    }

    balas
    0
  • PHP中文网

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

    Tukar kod di atas kepada 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)

    balas
    0
  • Batalbalas