String sub =StringUtils.substringBetween("a111b","a","b"); //截取 a111b中111
源码如下
public static final int INDEX_NOT_FOUND = -1;
public static String substringBetween(final String str, final String open, final String close) {
if (!ObjectUtils.allNotNull(str, open, close)) {
return null;
}
final int start = str.indexOf(open);
if (start != INDEX_NOT_FOUND) {
final int end = str.indexOf(close, start + open.length());
if (end != INDEX_NOT_FOUND) {
return str.substring(start + open.length(), end);
}
}
return null;
}
引入包内容如下
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency>