Unix Regular Expressions
What are RegExps?
RegExps, shorthand for regular expressions, are used in pattern matching and substitution operators. Regular expressions are actually a grammer for a little language. The regular expression interpreter (which we'll call the Engine) takes your grammer and compares it with the string you're doing pattern matching on. The Engine then returns a Boolean value, which depends on whether or not the string can be parsed as a sentence of your little language.
A regular expression is really just a sequence or a pattern of characters that is matched against a string of text when performing searches and replacements. A simple regular expression consists of a single character or a set of characters that matches itself.
Regexps are a very powerful tool. They pack a lot of meaning into a short space. Every single character in a regular expression has a special meaning. I once wasted several hours trying to fix a Perl script, only to find out later that I had forgotten a little "?", somewhere in one of the regular expressions I had constructed.
Many tasks can be done with regular expressions. The most common one is to find out whether a given string matches a particular pattern. You can also find out where the matching substring is located within the string. You can use a substitution command to replace matching sections with another string of your choice. The
split() operator returns an array of all substrings your pattern did not match.
Don't worry if you still don't quite understand what regexps are. You'll soon become a regular expression expert.
Created: October 23, 1997, 1997
Revised: December 4, 1997