Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

ed(1)

ex(1)

egrep(1)

fgrep(1)

grep(1)

REGEX(3)  —  UNIX Programmer’s Manual

NAME

regex, re_comp, re_exec, recmp, re_compile, re_match − regular expression handler

SYNOPSIS

char ∗re_comp(s)
char ∗s;

re_exec(s)
char ∗s;

recmp(pattern,target)
char ∗pattern, ∗target;

#include <regex.h>
struct regex {
charexpbuf[ESIZE];
char∗braslist[NBRA];
char∗braelist[NBRA];
charcircf;
char∗start, ∗end; /∗ pointers to occurrence in ’s’ ∗/
};
 struct regex ∗re_compile(s,fold)
char ∗s;
int fold;
 re_match(s,r)
char ∗s;
struct regex ∗r;

DESCRIPTION

Re_comp compiles a string into an internal form suitable for pattern matching. Re_exec checks the argument string against the last string passed to re_comp.

Re_comp returns 0 if the string s was compiled successfully; otherwise a string containing an error message is returned. If re_comp is passed 0 or a null string, it returns without changing the currently compiled regular expression. 

Re_exec returns 1 if the string s matches the last compiled regular expression, 0 if the string s failed to match the last compiled regular expression, and -1 if the compiled regular expression was invalid (indicating an internal error). 

Recmp is analogous to strcmp(3), but takes a regular expression pattern and returns 0 if it is matched in the target string, 1 if not, or -1 on error (bad regular expression). 

The strings passed to both re_comp and re_exec may have trailing or embedded newline characters; they are terminated by nulls.  The regular expressions recognized are described in the manual entry for ed(1), given the above difference.

Re_compile returns a pointer to a regex structure.  This information is also kept in the static area used by re_comp(); If the fold variable is true, the compiled regular expression will match either upper or lower case.  It may be deallocated with free().  Re_match is the same as re_exec with an explicit regex buffer.  After calling Re_match, the pointers r->start and r->end point to the beginning and end of the matched expression in s. 

SEE ALSO

ed(1), ex(1), egrep(1), fgrep(1), grep(1)

DIAGNOSTICS

Re_exec returns -1 for an internal error. 

Re_comp returns one of the following strings if an error occurs:

No previous regular expression

Regular expression too long

unmatched \(

missing ]

too many \(\) pairs

unmatched \)

Re_compile returns NULL for any of these errors. 

7th Edition  —  4 March 1983

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026