java 截取 <img src="/Libs/ueditor/net/upload/image/20190417/6369110621294028866831505.png" title="blob.png" alt="blob.png"/> 中src的数据
时间: 2023-12-17 21:05:20 浏览: 61
用java代码截图
可以使用正则表达式或者字符串处理的方式来截取。具体代码可以参考以下示例:
使用正则表达式截取:
```java
String str = "<img src=\"/Libs/ueditor/net/upload/image/20190417/6369110621294028866831505.png\" title=\"blob.png\" alt=\"blob.png\"/>";
Pattern pattern = Pattern.compile("<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>");
Matcher matcher = pattern.matcher(str);
if (matcher.find()) {
String src = matcher.group(1);
System.out.println(src);
}
```
使用字符串处理的方式截取:
```java
String str = "<img src=\"/Libs/ueditor/net/upload/image/20190417/6369110621294028866831505.png\" title=\"blob.png\" alt=\"blob.png\"/>";
String start = "src=\"";
String end = "\"";
int startIndex = str.indexOf(start) + start.length();
int endIndex = str.indexOf(end, startIndex);
String src = str.substring(startIndex, endIndex);
System.out.println(src);
```
以上代码输出结果都是:
```
/Libs/ueditor/net/upload/image/20190417/6369110621294028866831505.png
```
阅读全文