为什么 Visual Studio 使用这么奇怪的正则表达式语法 [英] Why does Visual Studio use such a strange regex syntax

查看:33
本文介绍了为什么 Visual Studio 使用这么奇怪的正则表达式语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual Studio 使用如此奇怪的语法(例如在搜索/替换对话框中)有什么原因吗?

Is there any reason why Visual Studio uses such a strange syntax (for instance in the search/replace dialog)?

不是写 \s*(\w+) = new Process\(\) 我必须写 :b*{:a+} = new Process\(\).
我一直在为这种语法苦苦挣扎 - 特别是因为正常的 .NET 语法是前者.

Instead of writing \s*(\w+) = new Process\(\) I have to write :b*{:a+} = new Process\(\).
I am always struggling with this syntax - especially since the normal .NET syntax is the former one.

这是两种语法之间的不完整比较:

This is an incomplete comparison between the two syntaxes:

What            Visual  .NET   Comment
                Studio
----------------------------------------------------------------
Tab/Spaces      :b       \s    Either tab or space
Alphanumeric    :a       \w    ([a-zA-Z0-9])
Subexpression   {}       ()
Substitution    \n       $n    Substitutes the substring matched 
                               by a numbered subexpression.
Backreference   \n       \n    Matches the value of a numbered 
                               subexpression.
----------------------------------------------------------------

请参阅此处(Visual StudioC#) 了解更多信息.

See here (Visual Studio, C#) for more information.

有什么原因吗?它是历史的吗?有什么优势吗?

Is there any reason for this? Is it historical? Is there any advantage?

推荐答案

我引用 Coding Horror:

I quote Coding Horror:

但是,您遇到了不愉快的事情当您尝试实际操作时感到惊讶使用正则表达式查找Visual Studio 中的任何内容.显然Visual Studio IDE 有自己的混杂的正则表达式语法.为什么?谁知道.大概是为了奥术向后兼容的原因,虽然我不知道你为什么想要永远发扬疯狂.显然它使人们亿万富翁,我该评判谁.

However, you're in for an unpleasant surprise when you attempt to actually use regular expressions to find anything in Visual Studio. Apparently the Visual Studio IDE has its own bastardized regular expression syntax. Why? Who knows. Probably for arcane backwards compatibility reasons, although I have no idea why you'd want to perpetually carry forward insanity. Evidently it makes people billionaires, so who am I to judge.

http://www.codinghorror.com/blog/2006/07/the-visual-studio-ide-and-regular-expressions.html

这篇关于为什么 Visual Studio 使用这么奇怪的正则表达式语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆