替换规则支持js,可以用js判断匹配到的内容决定替换为什么,匹配到的内容变量为result,替换为@js:开头则自动采用js判断替换内容

pull/2424/head
kunfei 2 years ago
parent 0280099ec3
commit ceca1a32d6
  1. 2
      app/src/main/java/io/legado/app/utils/RegexExtensions.kt

@ -29,7 +29,7 @@ suspend fun CharSequence.replace(regex: Regex, replacement: String, timeout: Lon
val stringBuffer = StringBuffer() val stringBuffer = StringBuffer()
while (matcher.find()) { while (matcher.find()) {
val bindings = SimpleBindings() val bindings = SimpleBindings()
bindings["result"] = matcher.group(1) bindings["result"] = matcher.group()
val jsResult = AppConst.SCRIPT_ENGINE.eval(js, bindings).toString() val jsResult = AppConst.SCRIPT_ENGINE.eval(js, bindings).toString()
matcher.appendReplacement(stringBuffer, jsResult) matcher.appendReplacement(stringBuffer, jsResult)
} }

Loading…
Cancel
Save