Click here to Skip to main content
15,893,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello experts!

I want to search criteria using
Regex for find all files which
contain word1 but
not contain word2
in visual studio project

please help
Posted

1 solution

So use two regexes:
C#
if (Regex.Match(inputfiletext, "word1").Success && !Regex.Match(inputfiletext, "word2").Success)
   {
   ...
   }
 
Share this answer
 
Comments
Aarti Meswania 28-Nov-13 6:55am    
Thank you OriginalGriff for kind response
I want to search my project files that fulfill above criteria in visual studio 2010 using Find and replace window that we open using ctrl+f shortcut...
could you please suggest regex for that I have tried many regex but didn't worked
OriginalGriff 28-Nov-13 7:12am    
Regex is not good at that kind of thing!
You can identify "does not contain" and "contains" but it's truly a PITA to do both, since you can only (AFAIK - I could be wrong) search for an absence of a prefix or suffix, so your search would have to allow for "word1 then word2" or "word2 then word1" - it's probably going to be easier and quicker to have two "find in files" lists and do it manually!

The problem is that with prefixes and suffixes it could easily get confused by "word1...word2...word1" and either find it when it shouldn't or not find it when it should... :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900