替换使用正则错误时替换为不使用正则

pull/1188/head
gedoor 3 years ago
parent 42b597ec1e
commit 4d5b73b9c5
  1. 16
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt

@ -340,15 +340,17 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions {
var vResult = result var vResult = result
if (rule.replaceRegex.isNotEmpty()) { if (rule.replaceRegex.isNotEmpty()) {
vResult = if (rule.replaceFirst) { vResult = if (rule.replaceFirst) {
val pattern = Pattern.compile(rule.replaceRegex) kotlin.runCatching {
val matcher = pattern.matcher(vResult) vResult.replaceFirst(rule.replaceRegex.toRegex(), rule.replacement)
if (matcher.find()) { }.getOrElse {
matcher.group(0)!!.replaceFirst(rule.replaceRegex.toRegex(), rule.replacement) vResult.replaceFirst(rule.replaceRegex, rule.replacement)
} else {
""
} }
} else { } 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 return vResult

Loading…
Cancel
Save