Regular Expressions
By Brian W. Kernighan and Rob Pike, April 01, 1999
Regular expressions, one of the most broadly applicable of programmer's tools, provide a compact and expressive notation for describing patterns of text. They are also algorithmically interesting, easy to implement, and highly useful. Brian and Rob, who are researchers at Bell Labs and the authors of The Practice of Programming, present a compact implementation of grep that uses regular expressions.
Apr99: Regular Expressions
/* match: search for re anywhere in text */
int match(char *re, char *text)
{
if (re[0] == '^')
return matchhere(re+1, text);
do { /* must look at empty string */
if (matchhere(re, text))
return 1;
} while (*text++ != '\0');
return 0;
}
Example 1: The function match determines whether a string matches a regular expression.
Copyright © 1999, Dr. Dobb's Journal