diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index a3496d9b5..47426834b 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -340,15 +340,17 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { var vResult = result if (rule.replaceRegex.isNotEmpty()) { vResult = if (rule.replaceFirst) { - val pattern = Pattern.compile(rule.replaceRegex) - val matcher = pattern.matcher(vResult) - if (matcher.find()) { - matcher.group(0)!!.replaceFirst(rule.replaceRegex.toRegex(), rule.replacement) - } else { - "" + kotlin.runCatching { + vResult.replaceFirst(rule.replaceRegex.toRegex(), rule.replacement) + }.getOrElse { + vResult.replaceFirst(rule.replaceRegex, rule.replacement) } } else { - vResult.replace(rule.replaceRegex.toRegex(), rule.replacement) + kotlin.runCatching { + vResult.replace(rule.replaceRegex.toRegex(), rule.replacement) + }.getOrElse { + vResult.replace(rule.replaceRegex, rule.replacement) + } } } return vResult