读取md内容中的图片地址

读取md内容中的图片地址

因为发布文章的内容图片上传到minio上, 为了减少空间占用, 所以需要删除文章的同时将内容中的图片也删除掉.

	/**
     * 将markdown中的图片地址取出
     * @param markdown  markdown内容
     */
    public static List<String> listPicUrlByMarkdown(String markdown) {
        List<String> matchList = getMatchList(markdown, "\\(.*\\)");
        String stringList = matchList.toString().replaceAll("\\(", "").replaceAll("\\[", "").replaceAll("]", "").replaceAll("\\)", "");
        String[] str = stringList.split(",");
        return Arrays.asList(str);
    }

    public static List<String> getMatchList(String markdown, String reg) {
        ArrayList<String> result = new ArrayList<>();
        Pattern pattern = Pattern.compile(reg, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(markdown);// 指定要匹配的字符串
        while (matcher.find()) { //此处find()每次被调用后,会偏移到下一个匹配
            result.add(matcher.group());//获取当前匹配的值
        }
        result.trimToSize();
        return result;
    }

因为正则表达式不太熟悉, 所以写的不太好, 暂时能用, 之后再改进.
参考链接

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值