From 4d5b73b9c54af1775c086a1e6a6eb4f559e5b3a1 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 29 Jul 2021 23:10:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E4=BD=BF=E7=94=A8=E6=AD=A3?= =?UTF-8?q?=E5=88=99=E9=94=99=E8=AF=AF=E6=97=B6=E6=9B=BF=E6=8D=A2=E4=B8=BA?= =?UTF-8?q?=E4=B8=8D=E4=BD=BF=E7=94=A8=E6=AD=A3=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/model/analyzeRule/AnalyzeRule.kt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) 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