You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Co-authored-by: Rachael Rose Renk <91027132+rachaelrenk@users.noreply.github.com> Co-authored-by: Sophie <29382425+sophietheking@users.noreply.github.com>
Copy file name to clipboardExpand all lines: content/search-github/github-code-search/understanding-github-code-search-syntax.md
+30-4Lines changed: 30 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,18 +51,26 @@ To search for an exact string, including whitespace, you can surround the string
51
51
"sparse index"
52
52
```
53
53
54
-
To search for a phrase containing a quotation mark, you can escape the quotation mark using a backslash. For example, to find the exact string `name = "tensorflow"`, you can search:
54
+
You can also use quoted strings in qualifiers, for example:
55
55
56
56
```text
57
-
"name = \"tensorflow\""
57
+
path:git language:"protocol buffers"
58
58
```
59
59
60
-
You can also use quoted strings in qualifiers, for example:
60
+
## Searching for quotes and backslashes
61
+
62
+
To search for code containing a quotation mark, you can escape the quotation mark using a backslash. For example, to find the exact string `name = "tensorflow"`, you can search:
61
63
62
64
```text
63
-
path:git language:"protocol buffers"
65
+
"name = \"tensorflow\""
64
66
```
65
67
68
+
To search for code containing a backslash, `\`, use a double backslash, `\\`.
69
+
70
+
The two escape sequences `\\` and `\"` can be used outside of quotes as well. No other escape sequences are recognized, though. A backslash that isn't followed by either `"` or `\` is included in the search, unchanged.
71
+
72
+
Additional escape sequences, such as `\n` to match a newline character, are supported in regular expressions. See "[Using regular expressions](#using-regular-expressions)."
73
+
66
74
## Using boolean operations
67
75
68
76
Code search supports boolean expressions. You can use the operators `AND`, `OR`, and `NOT` to combine search terms.
@@ -290,3 +298,21 @@ Note that you'll have to escape any forward slashes within the regular expressio
290
298
```text
291
299
/^App\/src\//
292
300
```
301
+
302
+
Inside a regular expression, `\n` stands for a newline character, `\t` stands for a tab, and `\x{hhhh}` can be used to escape any Unicode character. This means you can use regular expressions to search for exact strings that contain characters that you can't type into the search bar.
303
+
304
+
Most common regular expressions features work in code search. However, "look-around" assertions are not supported.
305
+
306
+
## Separating search terms
307
+
308
+
All parts of a search, such as search terms, exact strings, regular expressions, qualifiers, parentheses, and the boolean keywords `AND`, `OR`, and `NOT`, must be separated from one another with spaces. The one exception is that items inside parentheses, `(``)`, don't need to be separated from the parentheses.
309
+
310
+
If your search contains multiple components that aren't separated by spaces, or other text that does not follow the rules listed above, code search will try to guess what you mean. It often falls back on treating that component of your query as the exact text to search for. For example, the following query:
311
+
312
+
```text
313
+
printf("hello world\n");
314
+
```
315
+
316
+
Code search will give up on interpreting the parentheses and quotes as special characters and will instead search for files containing that exact code.
317
+
318
+
If code search guesses wrong, you can always get the search you wanted by using quotes and spaces to make the meaning clear.
0 commit comments