Text search examples
The following examples can help you understand how to use wildcards and regular expressions to perform more flexible searches for text in files. See Searching for text in files.
These examples only apply to searching for text in files in the Find in Files window. Additional wildcards and regular expressions may be supported when adding restrictions for advanced file searches or filters.
You can use wildcard characters to replace characters in search phrases. Wildcards are helpful if you are searching for terms with spelling variations or text that may include other characters, such as dashes. They are also helpful for finding partial word matches. For example, searching for 'run' does not find files that contain 'running' or 'homerun', but a wildcard search using '*run*' will find 'running' and 'homerun'.
To substitute for: | Use: | Example |
---|---|---|
Zero or more characters, excluding spaces | Asterisk (*) | 'gr*n' returns files that contain words such as 'green' and 'grain', but does not return phrases such as 'greater than'. |
One character, excluding spaces | Question mark (?) | 'p?int' returns files that contain words such as 'print', 'point', and 'paint'. |
You can use the following regular expression syntax and symbols to search for text in file contents. Regular expression searches only support individual terms. To search for a phrase, perform a search with or without wildcards.
To match: | Use: | Example |
---|---|---|
Any single character | . | ab. matches ‘ab’ followed by any character, such as 'abc' or 'ab_' |
Zero or one occurrence of the previous character | ? | colou?r matches 'color' or 'colour' |
One or more occurrences of the previous character | + | ba+ matches ‘b’ followed by any number of occurrences or ‘a’, such as 'ba', 'baa', or 'baaa' |
Zero or more occurrences of the previous character | * | a.* matches ‘a’ followed by any number of characters, such as 'ab', 'abb', 'aab', or 'aabb' |
Separate two or more alternatives to perform an OR search | | | (gray|grey) matches 'gray' or 'grey' |
A specified number of occurrences of the previous character | {...} | ba{3} matches 'baaa baa{3,} matches ‘b’ followed by three or more occurrences of ‘a’, such as 'baaa', 'baaaa', or 'baaaaa' |
Any single character included in a set of characters | [...] | [tw]alk matches 'talk' or 'walk' |
Group several items as a single unit | (...) | (file1|2|3|4) matches 'file1', 'file2', 'file3', or 'file4' |
Interpret special characters as exact literals | \ | file\.txt matches occurrences of 'file.txt' |