正則表達式匹配img標簽中的src獲取地址


import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class aa {

    public static void main(String[] args) {
        String htmlStr = "<img src='http://1231//1231/123/123.jpg' alt='圖片'>";
        Matcher m = Pattern.compile("src=\"?(.*?)(\"|>|\\s+)").matcher(htmlStr);
        String filePath = "";
        while(m.find())
        {    
            filePath = m.group(1);
        }
        System.out.println(filePath);
        System.out.println(filePath.substring(filePath.lastIndexOf("/")+1,filePath.length()-1));
    }

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 C#正則表達式提取HTML中IMG標簽中的SRC地址 C#正則表達式提取HTML中IMG標簽的SRC地址 匹配img標簽的正則表達式 正則表達式獲取字符串中的img標簽中的url鏈接 正則表達式匹配html標簽 正則表達式匹配標簽內的內容 javascript正則表達式:匹配所有html標簽 JS正則表達式匹配