gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 09:06:44 26 4
gpt4 key购买 nike

是否有任何原因导致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/3008010/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com