The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
regex.h File Reference

POSIX regular expressions, basic (BRE) and extended (ERE). More...

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

Go to the source code of this file.

Data Structures

struct  re_pattern_buffer
 a compiled expression (the layout is musl's) More...
struct  regmatch_t
 where a match (or a part of it) starts and ends; -1 when it did not match More...

Macros

#define REG_EXTENDED   1
#define REG_ICASE   2
#define REG_NEWLINE   4
#define REG_NOSUB   8
#define REG_NOTBOL   1
#define REG_NOTEOL   2
#define REG_OK   0
#define REG_NOMATCH   1
#define REG_BADPAT   2
#define REG_ECOLLATE   3
#define REG_ECTYPE   4
#define REG_EESCAPE   5
#define REG_ESUBREG   6
#define REG_EBRACK   7
#define REG_EPAREN   8
#define REG_EBRACE   9
#define REG_BADBR   10
#define REG_ERANGE   11
#define REG_ESPACE   12
#define REG_BADRPT   13
#define REG_ENOSYS   -1

Typedefs

typedef ssize_t regoff_t
typedef struct re_pattern_buffer regex_t
 a compiled expression (the layout is musl's)

Functions

int regcomp (regex_t *restrict preg, const char *restrict pattern, int cflags)
 compile pattern into preg: REG_OK, or an error for regerror
int regexec (const regex_t *restrict preg, const char *restrict text, size_t nmatch, regmatch_t *restrict pmatch, int eflags)
 match text against preg: REG_OK or REG_NOMATCH.
void regfree (regex_t *preg)
size_t regerror (int error, const regex_t *restrict preg, char *restrict buffer, size_t size)
 the message for an error into buffer (size bytes, cut if it is longer).

Detailed Description

POSIX regular expressions, basic (BRE) and extended (ERE).

The matcher is musl's (from TRE): see src/libc/src/regex/README.md.

Macro Definition Documentation

◆ REG_EXTENDED

#define REG_EXTENDED   1

◆ REG_ICASE

#define REG_ICASE   2

◆ REG_NEWLINE

#define REG_NEWLINE   4

◆ REG_NOSUB

#define REG_NOSUB   8

◆ REG_NOTBOL

#define REG_NOTBOL   1

◆ REG_NOTEOL

#define REG_NOTEOL   2

◆ REG_OK

#define REG_OK   0

◆ REG_NOMATCH

#define REG_NOMATCH   1

◆ REG_BADPAT

#define REG_BADPAT   2

◆ REG_ECOLLATE

#define REG_ECOLLATE   3

◆ REG_ECTYPE

#define REG_ECTYPE   4

◆ REG_EESCAPE

#define REG_EESCAPE   5

◆ REG_ESUBREG

#define REG_ESUBREG   6

◆ REG_EBRACK

#define REG_EBRACK   7

◆ REG_EPAREN

#define REG_EPAREN   8

◆ REG_EBRACE

#define REG_EBRACE   9

◆ REG_BADBR

#define REG_BADBR   10

◆ REG_ERANGE

#define REG_ERANGE   11

◆ REG_ESPACE

#define REG_ESPACE   12

◆ REG_BADRPT

#define REG_BADRPT   13

◆ REG_ENOSYS

#define REG_ENOSYS   -1

Typedef Documentation

◆ regoff_t

typedef ssize_t regoff_t

◆ regex_t

typedef struct re_pattern_buffer regex_t

a compiled expression (the layout is musl's)

Function Documentation

◆ regcomp()

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

compile pattern into preg: REG_OK, or an error for regerror

◆ regexec()

int regexec ( const regex_t *restrict preg,
const char *restrict text,
size_t nmatch,
regmatch_t *restrict pmatch,
int eflags )

match text against preg: REG_OK or REG_NOMATCH.

pmatch gets where the match and the first nmatch - 1 parts are.

◆ regfree()

void regfree ( regex_t * preg)

◆ regerror()

size_t regerror ( int error,
const regex_t *restrict preg,
char *restrict buffer,
size_t size )

the message for an error into buffer (size bytes, cut if it is longer).

Returns
the size the whole message needs, with its null byte.