O'Reilly logo

Advanced UNIX Programming by Warren W. Gay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Regular Expression Library

From the preceding discussion, you can appreciate that implementing regular expression searches on your own is less than trivial. However, regular expressions can be part of your programs with the help of the C library.

Compiling Regular Expressions

For efficiency, a regular expression is first compiled into an opaque data type regex_t. The function synopsis for compiling a regular expression is as follows:

#include <sys/types.h>
#include <regex.h>

int regcomp(regex_t *preg, const char *pattern, int cflags);

typedef struct {
    int         re_magic;
    size_t      re_nsub;   /* number of parenthesized subexpressions */
    const char  *re_endp;  /* end pointer for REG_PEND */
    struct re_guts *re_g;  /* opaque */
}  regex_t;

pattern is the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required