Visual Studio 2012-查找和替换 - 反向引用

Har*_*ari 4 regex replace visual-studio-2012

我有一个XML文件,并希望将每个时间值替换为秒到毫秒.

例如,替换time="250" to time="250000".

我尝试使用以下内容

Find: time="([0-9]*)"

Replace: time="$1000"
Run Code Online (Sandbox Code Playgroud)

但是,这似乎不起作用 - 它取代了time="250" to time="$1000".我能用这种方式解决这个问题吗?

Joe*_*eau 9

问题是你的替换不是$1,它是$1000.Visual Studio不知道您不希望在后向引用中包含这些3 0.

您可以{}在反向引用周围使用,告诉Visual Studio确切使用的内容.

Replace: time="${1}000"
Run Code Online (Sandbox Code Playgroud)

必须注意的是,Visual Studio 2010及更早版本使用了不同的正则表达式语法,因此这仅适用于Visual Studio 2012(可能是任何较新的版本).