Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In this movie, we'll take a look at the history of regular expressions. Now the history is not merely academic; it's actually important in understanding some of the key points in how regular expressions work. I think the most surprising part of the history of regular expressions is they first got their start in the field of neuroscience, way back in the 1940s. In 1943, McCulloch and Pitts developed models describing how the human nervous system works, or how a machine or a computer could be built to act more like a human brain. In 1956, Stephen Kleene described these models with an algebra that he called regular sets, and he created a notation to express them called regular expressions.
That's where we get the name from; Stephen Kleene is the one who coined it. But at this point, regular expressions have still not entered the computer world; they are not part of the digital age yet. It's not until 1968 when Ken Thompson, an early computer pioneer and one of the key developers of UNIX implemented regular expressions inside an early UNIX text editor that he was building called ed. This is the point at which regular expressions entered the computer world, and it happens right there at the birth of UNIX. So the future of regular expressions and UNIX is very much tied together.
Now if you were a user of this text editor, ed, and you wanted to search the text for a regular expression, you would do it by typing a g and then a forward slash, and then the set of symbols that made up through regular expression for what you wanted to search for, and then at the end, another forward slash and a p. The g and the p were modifiers. The g was telling you to globally search for this expression, search everywhere, and p was to output the results to the screen, to print them. So we end up with a global regular expression print, or for short, grep. It becomes a verb.
In the UNIX world, you're able to say, I want to grep something and it means that you want to search it for a regular expression. grep became so popular that it actually became a stand-alone program so that you could grep things in the UNIX file system as well, and it became widely used in other UNIX programs. So it really kind of spreads its way throughout the UNIX ecosystem. Now in my course UNIX for Mac OS X Users, I describe in some detail how UNIX became very popular during the 1970s. The short version of that story is it was high quality software that was free.
Furthermore, these two factors made it very attractive to universities, and these universities then taught the next generation of computer stars using UNIX. So it helped to spread not only UNIX, but regular expressions as well. Now throughout the 1970s, UNIX spreads in popularity and it begins to evolve. At the same time, grep begins to evolve as well. Now there's a problem with evolving the regular expression language. We have a set of symbols that clearly define something that matches and doesn't match.
Well, if you start changing the syntax of those symbols, then we create issues of backwards compatibility. Imagine if you had a basic character that didn't have a special meaning in one version, but then in a future version suddenly now that character has some special meaning. Well, all those old regular expressions would break; they would no longer match or the old engines would no longer be able to process the new regular expressions. In addition to grep, one of the early changes is to introduce a new program called egrep or extended grep. You can actually get the same behavior of egrep inside grep by using the E option after grep.
So grep-e is essentially the same thing as egrep, and it's saying, use this new modified syntax. So we're going to now have two flavors. We have the old ones and we have the new ones. Now over time these regular expressions continue to spread. There are many programs, there are more programmers, there's more changes, so we ended up with a lot more incompatibilities. So in 1986, everyone sits down and comes up with a standard, which they call POSIX, Portable Operating System Interface--the X is just because it's in UNIX.
So POSIX is a standard that is designed to ensure compatibility between different operating systems. So the first thing that it does is it says, all right, there are going to be two different kinds of regular expressions. There's going to be BREs, which are basic regular expressions, and that's essentially what grep is, and then there's going to be EREs which are extended regular expressions, and that's what egrep is. So now all programs and programmers have to decide, are we going to try and implement them in the flavor of BREs or EREs? And it's a very clearly defined set of rules about what should match and what shouldn't match, what symbols should mean something in each one of these.
Now it's not expected that BREs and EREs ought to be interchangeable, but at least we have two clear paths forward. And BRE is really maintained for compatibility in old tools--it becomes mostly out of use--and EREs is what most modern tools are going to use. So this big effort to sort of standardize everything really does a lot of good and really gets everyone sort of all get on the same page about how regular expressions ought to work. Now at this exact same time, Henry Spencer writes a regex library that's written in the C programming language.
And what's great about the fact that it's a library is that can be incorporated into other programs, and so it provides consistency because then everyone who uses his library, their regular expressions all work the same way. So things at this point have become more consistent and the changes to regular expressions have really stabilized. In 1987, Larry Wall releases the Perl programming language. It uses Spencer's regex library, but over time, it adds many more powerful features. Perl's real mission was to try and be a programming language that was designed to be really useful, and so it added more powerful features to make it more useful.
And just like Henry Spencer's library, it's a library that's supposed to add in all these extra features that Perl has. Now do you notice any similarity between Perl and most of those languages and programs that I've listed there? They're all tools that are used to build the Internet and websites. It was really the rise of the web that gave a big boost to the Perl implementation of regex, and that's where we get the modern syntax of regular expressions today; it really comes from Perl.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 96653 Viewers
56 Video lessons · 110364 Viewers
71 Video lessons · 79196 Viewers
131 Video lessons · 37977 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.