Question
We learn here that grep
stands for “global regular expression print”. What is a regular expression?
Answer
A regular expression is a technique for encoding a string pattern. By sting pattern, I mean that you decide on a specific set of rules that any string matching your expression should satisfy. For instance, say I want all strings which contain “Codecademy” as a substring where the letters within “Codecademy” can be either capital or lower case. For example, “CODECADEMY” is fine as is “CodeCadEMY”. Regular expressions provide a compact way of encoding this logic into a sequence of characters.
Although the example I presented is easy to program into a reasonably small function, regular expressions provide a consistent interface for performing arbitrary string matches; many of which would require large, error-prone, functions. The particular sequence which encodes a regular expression is similar but not the same across all languages. Because of this, if you’re interested in experimenting with regular expressions, find the syntax and library specific to your language of choice. You can find this by searching something along the lines of “regular expressions in <MY FAVORITE LANGUAGE>.”