RE(3)
β¨ NAME β¨
okay so bestie, this is RE(3) β the whole regular expression library situation β and the five functions in the group chat are recomp, reexec, ressub, refree, and reerror. that's the lineup. π
πΈ SYNOPSIS πΈ
#include <re.h>
Re_program_t* recomp(char* pattern, int flags);
int reexec(Re_program_t* re, char* source);
void ressub(Re_program_t* re, Sfio_t* sp, char* old, char* new, int flags);
void reerror(char* message);
void refree(Re_program_t* re);
π¦ DESCRIPTION π¦
recomp compiles the regular expression sitting in pattern and returns a pointer to the compiled regular expression. that space is allocated by malloc(3) and may be released by refree. the regex flavor is like egrep(1), except that newlines are treated as ordinary characters and $ matches the end of a null-terminated string. flags may be RE_EDSTYLE, which specifies ed(1)-style special characters: \(, \), \?, \+, and \| stand for egrep(1)'s (, ), ?, +, and |, respectively. β¨
reexec matches the null-terminated source string against the compiled regular expression re from a previous call to recomp. if it matches, reexec returns a non-zero value. if flags is RE_MATCH, then the array re->match is filled with character pointers to the substrings of source that correspond to the parenthesized subexpressions of pattern:
re->match[i].sppoints to the beginning of substringi.re->match[i].eppoints just beyond the end of substringi.- (subexpression
ibegins at theith matched left parenthesis, counting from 1.) - pointers in
re->match[0]pick out the substring that corresponds to the entire regular expression. - unused elements of
re->matchare filled with zeros.
matches involving *, +, and ? are extended as far as possible. a maximum of 9 subexpressions will be matched. the structure of elements of re->match is:
typedef struct
{
char* sp;
char* ep;
} rematch;
ressub places in the sfio(3) stream sp a substitution instance of old to new in source, in the context of the last reexec performed on re->match. each instance of \n, where n is a digit, is replaced by the string delimited by re->match[n].sp and re->match[n].ep. each instance of & is replaced by the string delimited by re->match[0].sp and re->match[0].ep. if RE_ALL is set in flags, then all occurrences of old are replaced by new. if RE_LOWER [RE_UPPER] is set in flags, then old is converted to lower [upper] case. π
reerror is called whenever an error is detected in recomp, reexec, or ressub; it writes the string msg on the standard error file and exits. reerror may be replaced to perform special error processing. π
π DIAGNOSTICS π
recomp returns 0 for an invalid expression or other failure. reexec returns 1 if source is accepted, 0 otherwise. that's the whole vibe check. β
π₯ SEE ALSO π₯
ed(1), grep(1), expr(1) β go read those too, bestie. π
that's the whole page! the footer is literally just RE(3) β no source/version line, no date, nothing else β so that's the sign-off. mwah πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: ksh-devel 93vu-bp160.1.33 Β· CPL-1.0
- opensuse-leap 16.0: ksh-devel 93vu-bp160.1.33 Β· CPL-1.0
- opensuse-leap 16.0: ksh-devel 93vu-bp160.1.33 Β· CPL-1.0
- opensuse-leap 16.0: ksh-devel 93vu-bp160.1.33 Β· CPL-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms