PCRE_COMPILE2(3)

πŸ’– PCRE_COMPILE2 πŸ’–

okay bestie, welcome to the PCRE_COMPILE2(3) page, straight out of the Library Functions Manual ✨ this is the one where we compile regexes and also get told exactly what went wrong, so pull up a chair 🫢


🌸 NAME 🌸

PCRE β€” Perl-compatible regular expressions πŸ’…


✨ SYNOPSIS ✨

no cap, this is literally the whole vibe:

#include <pcre.h>

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

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

pcre32 *pcre32_compile2(PCRE_SPTR32 pattern, int options,
     int *errorcodeptr,Β£
     const char **errptr, int *erroffset,
     const unsigned char *tableptr);

πŸ¦‹ DESCRIPTION πŸ¦‹

so this function compiles a regular expression into an internal form πŸŽ€ it's the same as pcre[16|32]_compile(), except it's got one extra little bestie along for the ride: the errorcodeptr argument 🫢

the arguments, let's go:

  • pattern β€” A zero-terminated string containing the regular expression to be compiled ✨
  • options β€” Zero or more option bits πŸ‘‘
  • errorcodeptr β€” Where to put an error code 🚨
  • 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 πŸŽ€

one bullet per bit, no skipping, we don't do that here:

  • 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 pcre16_compile() in UTF-16 mode
  • PCRE_UTF32 β€” Run pcre32_compile() in UTF-32 mode
  • PCRE_UTF8 β€” Run pcre_compile() in UTF-8 mode

🚨 bestie, real talk: 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 flags, no vibes. πŸ’€

πŸ’œ 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 πŸ’₯ fr fr, don't do it.

there's a complete description of the PCRE native API in the pcreapi page πŸ“š and a description of the POSIX API in the pcreposix page 🌸


🌈 SEE ALSO 🌈

  • pcreapi β€” the full native API tea β˜•
  • pcreposix β€” the POSIX API tea β˜•

and that's the whole page, bestie!! compiled with love by PCRE 8.34, dated 01 October 2013 πŸŽ€ mwah, go forth and match some patterns πŸ’…βœ¨πŸ¦‹