regex.h(0P)

🌸 PROLOG 🌸

okay bestie, before literally anything else β€” this manual page is part of the POSIX Programmer's Manual. πŸ’…

but real talk: the Linux implementation of this interface may differ (so go consult the corresponding Linux manual page for details of Linux behavior, fr), or the interface may not be implemented on Linux at all. 😭 imagine.


πŸŽ€ NAME πŸŽ€

regex.h β€” regular expression matching types

short, sweet, iconic, no notes. ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <regex.h>

that's the whole thing. she's lowkey minimal. 🫢


✨ DESCRIPTION ✨

so the <regex.h> header shall define the structures and symbolic constants used by the regcomp(), regexec(), regerror(), and regfree() functions. the whole squad, no cap. πŸ”₯

πŸ’œ the regex_t structure

The <regex.h> header shall define the regex_t structure type, which shall include at least this member:

    size_t    re_nsub    Number of parenthesized subexpressions.

(that's the number of parenthesized subexpressions, iykyk πŸ‘‘)

🌈 the size_t type

The <regex.h> header shall define the size_t type as described in <sys/types.h>. go read that one too, bestie.

🧚 the regoff_t type

The <regex.h> header shall define the regoff_t type as a signed integer type that can hold the largest value that can be stored in either a ptrdiff_t type or a ssize_t type. big enough for whatever you're throwing at it. πŸ’ͺ

πŸ’– the regmatch_t structure

The <regex.h> header shall define the regmatch_t structure type, which shall include at least these members:

    regoff_t    rm_so    Byte offset from start of string
                         to start of substring.
    regoff_t    rm_eo    Byte offset from start of string of the
                         first character after the end of substring.

so rm_so is where the substring starts and rm_eo is the byte right after it ends. the two of them are giving buddy-system energy. πŸŽ€

🌟 symbolic constants for the cflags parameter of regcomp()

The <regex.h> header shall define these:

  • REG_EXTENDED β€” Use Extended Regular Expressions.
  • REG_ICASE β€” Ignore case in match.
  • REG_NOSUB β€” Report only success or fail in regexec().
  • REG_NEWLINE β€” Change the handling of <newline>.

⭐ symbolic constants for the eflags parameter of regexec()

The <regex.h> header shall define these:

  • REG_NOTBOL β€” The <circumflex> character ('^'), when taken as a special character, does not match the beginning of string.
  • REG_NOTEOL β€” The <dollar-sign> ('$'), when taken as a special character, does not match the end of string.

πŸ’€ symbolic constants as error return values

The <regex.h> header shall define these:

  • REG_NOMATCH β€” regexec() failed to match.
  • REG_BADPAT β€” Invalid regular expression.
  • REG_ECOLLATE β€” Invalid collating element referenced.
  • REG_ECTYPE β€” Invalid character class type referenced.
  • REG_EESCAPE β€” Trailing <backslash> character in pattern.
  • REG_ESUBREG β€” Number in \digit invalid or in error.
  • REG_EBRACK β€” [] imbalance.
  • REG_EPAREN β€” \(\) or () imbalance.
  • REG_EBRACE β€” \{\} imbalance.
  • REG_BADBR β€” Content of \{\} invalid: not a number, number too large, more than two numbers, first larger than second.
  • REG_ERANGE β€” Invalid endpoint in range expression.
  • REG_ESPACE β€” Out of memory. 😭
  • REG_BADRPT β€” '?', '*', or '+' not preceded by valid regular expression.

🫢 the functions

The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided.

    int    regcomp(regex_t *restrict, const char *restrict, int);
    size_t regerror(int, const regex_t *restrict, char *restrict, size_t);
    int    regexec(const regex_t *restrict, const char *restrict, size_t,
               regmatch_t [restrict], int);
    void   regfree(regex_t *);

and one more thing πŸ‘‡

The implementation may define additional macros or constants using names beginning with REG_.

The following sections are informative.


🌷 APPLICATION USAGE 🌷

None.

literally nothing. she said no thoughts, head empty. πŸ™ˆ


🌺 RATIONALE 🌺

None.

also nothing. πŸ’…


πŸ¦„ FUTURE DIRECTIONS πŸ¦„

None.

(the future is, apparently, unwritten. periodt.)


πŸ‘‘ SEE ALSO πŸ‘‘

  • <sys_types.h>
  • The System Interfaces volume of POSIX.1‐2017, regcomp()

okay so legally speaking, here's the whole notice, keeping it 100% intact because lawyers are not a vibe to mess with:

Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page, bestie!! πŸ¦‹ this one came to you courtesy of IEEE/The Open Group, dated 2017 β€” mwah, thanks for the lore, now go match some regexes responsibly. πŸ’œβœ¨πŸŽ€

πŸ“¦ where this page comes from