Until today, I wasn't aware of the ability to search for code with special symbols within our normal search. It's actually easy:

Instead of #include, search for code:#include.

(There appear to be some limitations on this, since HTML "tags" appear to be stripped.)

It's clear that nobody really knows about this. Of course, I already answered this question with this solution, but I also think it should be mentioned prominently in the search help, especially the "Advanced Search Tips".


The hascode: operator is also unlisted. It's not as helpful, but you can use it to avoid all the questions with no code, at least now that you know about it.

share
66  
Hey, I didn't know about this. +1. – Frédéric Hamidi Aug 7 at 21:37
27  
Yeah, this came up here also. This should be documented clearly, but from this comment: That being said, I don't feel it's 1.0 quality at this point, so haven't added it to documentation as I expect there are bugs I'll find with more testing locally... The situation perhaps changed since 2012. – Tunaki Aug 7 at 21:40
37  
Your question title is about special characters, your question body is about limiting searches to code. They are two separate things. – hvd Aug 8 at 1:49
4  
@hvd True, but I fixed it now. In reality, the operator does search code, but its significance is obviously the ability to search for symbols. While some languages (SQL or AppleScript come to mind) have "search friendly" syntax, many languages don't. (Regex is usually 90+% symbols.) – Laurel Aug 8 at 1:56
2  
@tunaki Unfortunately, I'll bet the interruptions for poor Nick haven't ceased since 2012. – Cody Gray Aug 8 at 12:20
    
stackoverflow.com/search?q=code%3A%24foo does not work as expected... – Tschallacka Aug 8 at 13:01
6  
@MichaelDibbets With quotes around, it appears to work. – Tunaki Aug 8 at 13:02
13  
@Tunaki What if we want code with "$foo" in it, not $foo? This lack of polish clearly indicates why it should not be documented and used. Foo on this feature! Foo I say. Dollar sign. – Yakk Aug 8 at 19:11
    
I always found it so annoying that I couldn't search for code. Very useful! – Suragch Aug 8 at 19:59
    
@hvd: The two are not separate things, because code search is handled differently, and it;s this code search which handles non-alphanumeric characters. – MSalters Aug 10 at 9:41
    
recent experience has me laughing about lucene syntax. That is all. – Peter LaComb Jr. Oct 26 at 19:48

Some of these features were hinted at in 2012 and 2014 on Meta.SE:

Quoted phrases are exact matches except for case-sensitivity, for example, you can search for code or symbols.

The built-in Elastic Search will allow you to search for operators using their literal symbols, such as * and & instead of using "asterisk" and "ampersand", respectively:

References

share

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .