gpt4 book ai didi

regex - VSCode 正则表达式使用正则表达式组替换

转载 作者:行者123 更新时间:2023-12-05 02:31:39 26 4
gpt4 key购买 nike

我想用 (map["someKey"] as num).toDouble() 替换 map["someKey"] as double,但我不能'无法让正则表达式正常工作。对正则表达式了解更多的人可以告诉我在 VSCode 中的查找和替换中放什么吗?我试过 ([a-zA-Z0-9]*) as double 并将其替换为 ($1 as num).toDouble(),但这并没有不工作。

最佳答案

使用

(\w+\["[^"]+"\]) as double

参见 regex proof . 替换为 ($1 as num).toDouble()

解释

--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
\w+ word characters (a-z, A-Z, 0-9, _) (1 or
more times (matching the most amount
possible))
--------------------------------------------------------------------------------
\[ '['
--------------------------------------------------------------------------------
" '"'
--------------------------------------------------------------------------------
[^"]+ any character except: '"' (1 or more
times (matching the most amount
possible))
--------------------------------------------------------------------------------
"\] '"]'
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
as double ' as double'

关于regex - VSCode 正则表达式使用正则表达式组替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71488807/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com