How do I find {min, max} repeats regex patterns in Visual Studio or SSMS Find and Replace?

I knew that we had something similar in the world of regular expression syntax.

* Syntax: {min, max}, where min is a positive integer 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, and {1,} matches +

http://www.regular-expressions.info/repeat.html


but how can I use it in the SQL Server Management Studio or Visual Studio Find and Replace window. I just found Microsoft related syntax on MSDN . How:

[0-9] ^ 4 matches any 4-digit sequence.

+6
regex visual-studio ssms
source share
1 answer

The implementation of Visual Studio (in versions up to VS 2010) is rather non-standard, and at least it does not have this function. You can only specify:

* or @ : match zero or more of the previous expression

+ or # : match one or more of the previous expression

^n : Match exactly n repetitions of the previous expression

So, for A{2,4} you will need to use A^4|A^3|A^2 (see the polygenelubricant comment for an explanation of why you need to do this in descending order).

Later versions of VS support the entire set of .NET regular expressions.

+10
source share

All Articles