正则表达式替换值

伊娃

输入:

.city.playground[?(@.playhouse == 'true' && @.IsPoolAvailable=='true')].checked]

输出:

.city.poolavailable.checked

正则表达式将输入转换为输出:

result = result.replace("playground[?(@.playhouse == 'true' && @.IsPoolAvailable=='true')]",'poolavailable');

此正则表达式不会呈现预期的输出。请帮助使用任何其他正则表达式。

CinCout

您需要在正则表达式中转义特殊字符。采用:

playground\[\?\(@\.playhouse\s*==\s*'true'\s+&&\s+@\.IsPoolAvailable\s*==\s*'true'\)\](\.\S+)\]

然后将匹配项替换为poolavailable$1

result = result.replace("playground\[\?\(@\.playhouse\s*==\s*'true'\s+&&\s+@\.IsPoolAvailable\s*==\s*'true'\)\](\.\S+)\]", "poolavailable$1");

演示版

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章