I knew that we have something like this in the regular expression syntax world.
*The syntax is {min,max}, where min
is a positive integer number indicating the minimum number of matches, and max
is an integer equal to or greater than min
indicating the maximum number of matches.
So {0,}
is the same as *
, and {1,}
is the same as +*
.
http://www.regular-expressions.info/repeat.html
But how can I use it in SQL Server Management Studio or Visual Studio's "Find and Replace" window. I only find relate开发者_开发知识库d Microsoft syntax in MSDN. Like:
[0-9]^4 matches any 4-digit sequence.
The Visual Studio regex implementation (in versions up until Visual Studio 2010) is a fairly nonstandard one to say the least, and it doesn't have this feature. You can only spell it out:
*
or @
: Match zero or more of the preceding expression
+
or #
: Match one or more of the preceding expression
^n
: Match exactly n repetitions of the preceding expression
So for A{2,4}
you'd have to use A^4|A^3|A^2
(see polygenelubricant's comment for an explanation why you need to do it in descending order).
More recent versions of Visual Studio support the entire set of .NET regexes.
精彩评论