Github case sensitive regex search


If you want to use regular expressions with Github’s new code search you can, but be aware that some functionality is not implemented yet. I learned today that the regex search is case insensitive by default, which is the oppositive of what one expects of a regex search. The reason for this is the new search index, which is case insensitive which in turns means that case sensitive search is inefficient. According to github this will be fixed sometime in the future.

In the meantime you can use inline regex options as a workaround. For example:

Let say you want to find occurrences of Object( in the code.

Object\( - would be the usual regex

(?-i)Object\( - is the github modified regex to achieve the same result

/(?-i)Object\(/ - is the final query string which can be put into Github’s search box

The github search expects regular expressions to be surrounded by slashes.

The (?-i) is a negated inline regex option. Since case insensitive search is on we use the - sign to turn it off. Github’s search uses as a regex engine, so whatever that engine can parse should theoretically also work.

Snippetsgithubregexregex inline optionssearchTIL

WARNING: your terminal doesn't support cursor position requests (CPR).