我可以使用正则表达式在 Resharper 的自定义模式中查找字符串吗?

Can I use regex to find strings in Resharper's Custom Patterns?

我们的代码库有很多 StringBuilder.AppendFormats 包含以换行符结尾的字符串。我制作了一个名为 AppendLineFormat 的扩展方法,并希望使用 Resharper 的自定义模式功能来识别和修复那些旧调用以使用新的扩展方法(并在将来向其他人推荐这种新的扩展方法)。

StringBuilder sb = new StringBuilder();
int i = 1;
sb.AppendFormat("i is {0}\r\n", i);

进入

sb.AppendLineFormat("i is {0}", i);

有没有办法使用正则表达式(带替换)来识别匹配的字符串?我不想将每个 AppendFormat 都变成 AppendLineFormat - 只有字符串以 \r\n 结尾的那些。这是我到目前为止所得到的。

搜索模式:

$sb$.AppendFormat($newLineString$,$args$)

替换模式:

$sb$.AppendLineFormat($newLineString$,$args$)

在哪里

很遗憾,目前还不支持。

有一堆问题,你可以投票给他们:

作为解决方法,您可以使用 Visual Studio 查找和替换功能。

搜索模式:

\.AppendFormat\(\"(.+?)(?>\r\n\")

替换模式:

.AppendLineFormat(""