
86
|
Chapter 3, Navigating Visual Studio
#19 Search for Patterns in Your Files
HACK
more than one range, simply add it to the first, so [a-z0-9] will match any
letter or number. Regular expression characters in Visual Studio are not case
sensitive unless you select the Match Case option in the Find dialog. This is
a departure from most other regular expression syntax.
Normal alphabetic characters outside of special expressions match charac-
ters literally, similar to a normal Find, but can be combined with regular
expressions to make them more flexible. This means that combining the set
match with a literal match gives us a pattern such as
var[12], which will
match
var1 and var2 but not var3.
If you want to match the string var[12], you’d need to
escape the special characters, as in
var\[12\].
Matching quantities. Matching a single character isn’t particularly useful, so
you want to be able to specify a quantity. You can either specify an exact
number of times with the pattern
^n, where n is the number of matches you
are seeking, or use
*, which will match 0 or more repetitions of the pattern.
Thus,
[abcd]* would match ababcd, a, or an empty string, but not abzd.If
you want to be sure that there is at least one match, you can use the
+ char-
acter, which matches one or more repetitions of the pattern.
Preventing matches. Sometimes preventing a match is the desired behavior.
The pattern
bool~(ean) uses the