开发者

Complete Regex syntax for Sql Server Management Studio

开发者 https://www.devze.com 2023-03-15 09:54 出处:网络
Is there a complete description of the regular expression syntax used in Sql Server Management Studio?There must be a way to do negative lookaheads, for examp开发者_Go百科le, but the find/replace dial

Is there a complete description of the regular expression syntax used in Sql Server Management Studio? There must be a way to do negative lookaheads, for examp开发者_Go百科le, but the find/replace dialog doesn't list one.


SSMS versions 2005-2012 are really just modified/customized Visual Studio Shell (2005-2010) environments, so this Visual Studio (2005-2010) Regular Expression reference applies:

http://msdn.microsoft.com/en-us/library/2k3te2cs(v=vs.80).aspx

Visual Studio 2012 and later have switched to standard .Net regular expressions.

However SSMS did not follow suit and adapt standard regular expressions until SSMS 2016.


SSMS uses a qurky RegEx implementation that is very different from what is used in Visual Studio and in the .NET Regex class.

A complete list if its capabilities and their corresponding syntax can be found here at MSDN.

Even with the documentation to its bizarre dialect of regular expressions, you may find its feature set quite lacking. (Examples: It doesn't support basics like the "?" operator or useful advanced things like positive look around.) You can do negative look arounds with this syntax:

Prevent match    ~(X)    Prevents a match when X appears at this point in the
                         expression. For example, real~(ity) matches the "real" 
                         in "realty" and "really," but not the "real" in "reality."

The only benefit I've seen of the quirky SSMS dialect is that it does contain a lot of built-in character classes not seen in many other engines.
Examples:

Math symbol       :Sm   Matches +, =, ~, |, <, and >.
Currency symbol   :Sc   Matches $ and other currency symbols.

NOTE FOR THOSE WHO ALREADY USE REGULAR EXPRESSIONS ELSEWHERE:

Realistically, unless you intend on making a LOT of usage of the custom groups it contains, it probably will not be worth your time to learn this bizarre dialect of Regex. Copy your query over to an editor with a more standard implementation (visual studio 2012 or later, notepad++, etc.) and you will be better served.

0

精彩评论

暂无评论...
验证码 换一张
取 消