如何用正则表达式替换文本?

How to replace text with regex?

如何在 Visual Studio 的查找和替换中编写正则表达式以更改以下文本的所有实例:

If (whatever control and overloads) = "" then

为此:

String.IfNullorEmpty(whatever control and overloads) then

搜索:

If (.*) \= "" Then

并替换为:

String.IfNullOrEmpty() Then

尽管如此,我认为您的实际意思是:

If String.IsNullOrEmpty() Then

诀窍是简单地将模式的所需部分括在括号中,使其成为 RegEx 组。然后在替换字符串中,您可以使用 $ 语法引用组。