add - bili90

This commit is contained in:
yangqiang3504
2022-09-01 17:00:43 +08:00
parent d4008c1d08
commit 604cbd34d4
3 changed files with 13 additions and 46 deletions
@@ -244,31 +244,17 @@ public class Misc {
public static ArrayList<String> subContent(String content, String startFlag, String endFlag) {
ArrayList<String> result = new ArrayList<>();
if (startFlag.isEmpty() && endFlag.isEmpty()) {
result.add(content);
return result;
}
try {
Pattern pattern = Pattern.compile(escapeExprSpecialWord(startFlag) + "(.*?)" + escapeExprSpecialWord(endFlag));
Matcher matcher = pattern.matcher(content);
while (matcher.find()) {
result.add(matcher.group(1));
if (content != null && content.length() > 1) {
try {
Pattern pattern = Pattern.compile(startFlag + "(.*?)" + endFlag);
Matcher matcher = pattern.matcher(content);
while (matcher.find()) {
result.add(matcher.group(1));
}
} catch (Throwable th) {
th.printStackTrace();
}
} catch (Throwable th) {
th.printStackTrace();
}
return result;
}
public static String escapeExprSpecialWord(String regexStr) {
if (!regexStr.isEmpty()) {
String[] fbsArr = {"\\", "$", "(", ")", "*", "+", ".", "[", "]", "?", "^", "{", "}", "|"};
for (String key : fbsArr) {
if (regexStr.contains(key)) {
regexStr = regexStr.replace(key, "\\" + key);
}
}
}
return regexStr;
}
}