Rob
Rob

Reputation: 10248

regex search in vs2010

How can I perform a case insensitive search that will find two words that may or may not have a space between them in Visual Studio 2010 e.g.

Foo Bar

FooBar

fooBar

foo bar

EDIT:

Sorry I should have been clearer - I mean a ctrl+shift+f (Edit -> Find and Replace -> Find in Files) search in VS2010 - I don't want to implement this in code - I want to find code/comments etc that matches the search criteria above.

I could also just do four searches... but I am interested to know how to do this in one go, and I would feel more comfortable doing it in one go as I am refactoring.

Cheers Rob

Upvotes: 2

Views: 346

Answers (2)

Rob Smyth
Rob Smyth

Reputation: 1858

Use the regex:

foo:b*bar

In VS search form: enter image description here

In code Regex has a case sensitivity option.

Upvotes: 2

escargot agile
escargot agile

Reputation: 22379

You could do it with a single regular expression, but I believe the code will be more readable if you handle each case seprately. Check if the string looks like "FooBar" (maybe using a regex), and if it doesn't, just count the number of spaces in the string (you can use Trim()) to eliminate the leading and training spaces).

Upvotes: 1

Related Questions