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

pull/1188/head
gedoor 3 years ago
parent 42b597ec1e
commit 4d5b73b9c5
  1. 14
      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 {
kotlin.runCatching {
vResult.replace(rule.replaceRegex.toRegex(), rule.replacement)
}.getOrElse {
vResult.replace(rule.replaceRegex, rule.replacement)
}
}
}
return vResult

Loading…
Cancel
Save