简体   繁体   English

Visual Studio 2010 Lazily量化正则表达式替换

[英]Visual Studio 2010 Lazily Quantified Regex Replace

Is there a way to do a non-greedy Regex replace / Regex find in VS 2010? 有没有办法在VS 2010中进行非贪婪的正则表达式替换/正则表达式查找?

I mean for the find-and-replace feature in visual studio: NOT a regex.replace method. 我的意思是visual studio中的find-and-replace功能:不是regex.replace方法。

I'm doing something like this to remove terrible exception handling: 我正在做这样的事情来消除可怕的异常处理:

Find: Catch <.*> As Exception(.*\n)*.*End Try

but because the (.*\\n)* is greedy, it won't behave like I want it to (and it takes forever). 但是因为(.*\\n)*是贪婪的,它不会表现得像我想要的那样(并且它需要永远)。

Here's an example of something that doesn't match correctly: 这是一个不正确匹配的例子:

Try
    'blah blah blah
Catch ex As Exception
End Try
Try
    'blah blah blah
Catch ex As Exception
End Try

Yes: use an at sign ( @ ). 是的:使用at符号( @ )。

In VS 2010: 在VS 2010中:

ab@c

Is equivalent to: 相当于:

ab*?c

It was pretty lame, but they've fortunately changed it all in newer versions of Visual Studio. 它非常蹩脚,但幸运的是他们在较新版本的Visual Studio中改变了这一点。

In your example, it would be this: 在您的示例中,它将是这样的:

Find: Catch <.@> As Exception(.@\n)@.@End Try

Documentation here . 文档在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM