regex - 为什么 Visual Studio 使用如此奇怪的正则表达式语法

标签 regex visual-studio-2008 syntax

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

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

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

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#)。

这有什么原因吗?它是历史的吗?有什么好处吗?

最佳答案

我引用编码恐怖:

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

关于regex - 为什么 Visual Studio 使用如此奇怪的正则表达式语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7899355/

相关文章:

python 用逗号分割字符串而不是在矩阵表达式内

java - 最大的行和列 Java 正则表达式

c++ - 在 xp 中将 Cuda 与基于表单的 GUI 结合使用

python - 类型错误 : writelines() requires an iterable argument

c++ - 电影中的代码不清楚。这合法吗?

python - 在 Python 2.7 中根据正则表达式匹配重新排序列表?

python - 正则表达式优化 - C enum typedef

c++ - 如何在 Visual Studio 中强制输出构建错误的绝对路径

visual-studio - 明确设置目标平台时未构建新项目

c# - ASP.NET - @ 语法和 <% %> 之间的区别?