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

This commit is contained in:
kunfei
2022-10-13 17:14:59 +08:00
parent 83d03ad48b
commit f507ea0c5c
@@ -29,7 +29,7 @@ suspend fun CharSequence.replace(regex: Regex, replacement: String, timeout: Lon
val stringBuffer = StringBuffer()
while (matcher.find()) {
val bindings = SimpleBindings()
bindings["result"] = matcher.group(1)
bindings["result"] = matcher.group()
val jsResult = AppConst.SCRIPT_ENGINE.eval(js, bindings).toString()
matcher.appendReplacement(stringBuffer, jsResult)
}