Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RegEx to match C# Interface file names only

In the Visual Studio 2010 "Productivity Power Tools" plugin (which is great), you can configure file tabs to be color coded based on regular expressions.

I have a RegEx to differentiate the tab color of Interface files (IMyInterface.cs) from regular .cs files:

[I]{1}[A-Z]{1}.*\.cs$

Unfortunately this also color codes any file that starts with a capital "I" (Information.cs, for example).

How could this RegEx be modified to only include files where the first letter is "I" and the second letter is not lowercase?

like image 651
Guy Starbuck Avatar asked Mar 11 '11 14:03

Guy Starbuck


People also ask

Can you use regex in C?

It is used in every programming language like C++, Java, and Python. Used to find any of the characters or numbers specified between the brackets.

What is the pattern matching in C?

Pattern matching in C− We have to find if a string is present in another string, as an example, the string "algorithm” is present within the string "naive algorithm". If it is found, then its location (i.e. position it is present at) is displayed.

What does ?= Mean in regular expression?

?= is a positive lookahead, a type of zero-width assertion. What it's saying is that the captured match must be followed by whatever is within the parentheses but that part isn't captured. Your example means the match needs to be followed by zero or more characters and then a digit (but again that part isn't captured).

How do I return a regex match?

You can retrieve subsequent matches by repeatedly calling the returned Match object's Match. NextMatch method. You can also retrieve all matches in a single method call by calling the Regex. Matches(String, Int32) method.


1 Answers

Your regexp should work as it is. It is possible that it is executed in ignore case mode. Try to disable that mode inside your regexp with (?-i):

(?-i)[I]{1}[A-Z]{1}.*\.cs$
like image 105
Maxim Gueivandov Avatar answered Oct 08 '22 21:10

Maxim Gueivandov