PCRE_COMPILE(3)

🌸 NAME 🌸

hii bestie, welcome to PCRE_COMPILE(3), hanging out under the Library Functions Manual umbrella πŸ’– this whole page is about PCRE β€” that's Perl-compatible regular expressions β€” and no cap, it's iconic.


✨ SYNOPSIS ✨

#include <pcre.h>

pcre *pcre_compile(const char *pattern, int options,
     const char **errptr, int *erroffset,
     const unsigned char *tableptr);

pcre16 *pcre16_compile(PCRE_SPTR16 pattern, int options,
     const char **errptr, int *erroffset,
     const unsigned char *tableptr);

pcre32 *pcre32_compile(PCRE_SPTR32 pattern, int options,
     const char **errptr, int *erroffset,
     const unsigned char *tableptr);

πŸ’… DESCRIPTION πŸ’…

okay so, what this function does is compile a regular expression into an internal form ✨ it is literally the same as pcre[16|32]_compile2(), with exactly one difference: there's no errorcodeptr argument. that's it, that's the whole tea πŸ“

the arguments are giving very much:

  • pattern β€” a zero-terminated string containing the regular expression to be compiled
  • options β€” zero or more option bits
  • errptr β€” where to put an error message
  • erroffset β€” offset in pattern where error was found
  • tableptr β€” pointer to character tables, or NULL to use the built-in default

πŸ‘‘ the option bits πŸ‘‘

these are the little flags you can OR together, and every single one of them matters, so buckle up:

  • PCRE_ANCHORED β€” force pattern anchoring
  • PCRE_AUTO_CALLOUT β€” compile automatic callouts
  • PCRE_BSR_ANYCRLF β€” \R matches only CR, LF, or CRLF
  • PCRE_BSR_UNICODE β€” \R matches all Unicode line endings
  • PCRE_CASELESS β€” do caseless matching
  • PCRE_DOLLAR_ENDONLY β€” $ not to match newline at end
  • PCRE_DOTALL β€” . matches anything including NL
  • PCRE_DUPNAMES β€” allow duplicate names for subpatterns
  • PCRE_EXTENDED β€” ignore white space and # comments
  • PCRE_EXTRA β€” PCRE extra features (not much use currently)
  • PCRE_FIRSTLINE β€” force matching to be before newline
  • PCRE_JAVASCRIPT_COMPAT β€” JavaScript compatibility
  • PCRE_MULTILINE β€” ^ and $ match newlines within data
  • PCRE_NEVER_UTF β€” lock out UTF, e.g. via (*UTF)
  • PCRE_NEWLINE_ANY β€” recognize any Unicode newline sequence
  • PCRE_NEWLINE_ANYCRLF β€” recognize CR, LF, and CRLF as newline sequences
  • PCRE_NEWLINE_CR β€” set CR as the newline sequence
  • PCRE_NEWLINE_CRLF β€” set CRLF as the newline sequence
  • PCRE_NEWLINE_LF β€” set LF as the newline sequence
  • PCRE_NO_AUTO_CAPTURE β€” disable numbered capturing parentheses (named ones available)
  • PCRE_NO_AUTO_POSSESS β€” disable auto-possessification
  • PCRE_NO_START_OPTIMIZE β€” disable match-time start optimizations
  • PCRE_NO_UTF16_CHECK β€” do not check the pattern for UTF-16 validity (only relevant if PCRE_UTF16 is set)
  • PCRE_NO_UTF32_CHECK β€” do not check the pattern for UTF-32 validity (only relevant if PCRE_UTF32 is set)
  • PCRE_NO_UTF8_CHECK β€” do not check the pattern for UTF-8 validity (only relevant if PCRE_UTF8 is set)
  • PCRE_UCP β€” use Unicode properties for \d, \w, etc.
  • PCRE_UNGREEDY β€” invert greediness of quantifiers
  • PCRE_UTF16 β€” run in pcre16_compile() UTF-16 mode
  • PCRE_UTF32 β€” run in pcre32_compile() UTF-32 mode
  • PCRE_UTF8 β€” run in pcre_compile() UTF-8 mode
🫢 real talk though: PCRE must be built with UTF support in order to use PCRE_UTF8/16/32 and PCRE_NO_UTF8/16/32_CHECK, and with UCP support if PCRE_UCP is used. no build flag, no vibes, no exceptions.

🌈 what you get back 🌈

the yield of the function is a pointer to a private data structure that contains the compiled pattern, or NULL if an error was detected πŸ‘‘

πŸ’€ and listen: compiling regular expressions with one version of PCRE for use with a different version is not guaranteed to work and may cause crashes. that's not a vibe check you want to fail, bestie. fr fr.

also, for the record: there is a complete description of the PCRE native API in the pcreapi page, and a description of the POSIX API in the pcreposix page 🌸 go read those next, iykyk.


and that's the whole page, periodt πŸŽ€ this was PCRE_COMPILE(3) from PCRE 8.34, dated 01 October 2013 β€” mwah, go compile something beautiful πŸ’–βœ¨