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 compiledoptionsβ zero or more option bitserrptrβ where to put an error messageerroffsetβ offset inpatternwhere error was foundtableptrβ pointer to character tables, orNULLto 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 anchoringPCRE_AUTO_CALLOUTβ compile automatic calloutsPCRE_BSR_ANYCRLFβ\Rmatches only CR, LF, or CRLFPCRE_BSR_UNICODEβ\Rmatches all Unicode line endingsPCRE_CASELESSβ do caseless matchingPCRE_DOLLAR_ENDONLYβ$not to match newline at endPCRE_DOTALLβ.matches anything including NLPCRE_DUPNAMESβ allow duplicate names for subpatternsPCRE_EXTENDEDβ ignore white space and#commentsPCRE_EXTRAβ PCRE extra features (not much use currently)PCRE_FIRSTLINEβ force matching to be before newlinePCRE_JAVASCRIPT_COMPATβ JavaScript compatibilityPCRE_MULTILINEβ^and$match newlines within dataPCRE_NEVER_UTFβ lock out UTF, e.g. via(*UTF)PCRE_NEWLINE_ANYβ recognize any Unicode newline sequencePCRE_NEWLINE_ANYCRLFβ recognize CR, LF, and CRLF as newline sequencesPCRE_NEWLINE_CRβ set CR as the newline sequencePCRE_NEWLINE_CRLFβ set CRLF as the newline sequencePCRE_NEWLINE_LFβ set LF as the newline sequencePCRE_NO_AUTO_CAPTUREβ disable numbered capturing parentheses (named ones available)PCRE_NO_AUTO_POSSESSβ disable auto-possessificationPCRE_NO_START_OPTIMIZEβ disable match-time start optimizationsPCRE_NO_UTF16_CHECKβ do not check the pattern for UTF-16 validity (only relevant ifPCRE_UTF16is set)PCRE_NO_UTF32_CHECKβ do not check the pattern for UTF-32 validity (only relevant ifPCRE_UTF32is set)PCRE_NO_UTF8_CHECKβ do not check the pattern for UTF-8 validity (only relevant ifPCRE_UTF8is set)PCRE_UCPβ use Unicode properties for\d,\w, etc.PCRE_UNGREEDYβ invert greediness of quantifiersPCRE_UTF16β run inpcre16_compile()UTF-16 modePCRE_UTF32β run inpcre32_compile()UTF-32 modePCRE_UTF8β run inpcre_compile()UTF-8 mode
π«Ά real talk though: PCRE must be built with UTF support in order to usePCRE_UTF8/16/32andPCRE_NO_UTF8/16/32_CHECK, and with UCP support ifPCRE_UCPis 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 πβ¨
π¦ where this page comes from
- alpine 3.22: pcre-doc 8.45-r4 Β· BSD-3-Clause
- alpine 3.23: pcre-doc 8.45-r4 Β· BSD-3-Clause
- alpine 3.24: pcre-doc 8.45-r4 Β· BSD-3-Clause
- arch rolling: pcre 8.45-5 Β· BSD
- centos-stream 9: pcre-devel 8.44-4.el9 Β· BSD
- centos-stream 9: pcre-devel 8.44-4.el9 Β· BSD
- debian bookworm: libpcre3-dev 2:8.39-15
- fedora 43: pcre-devel 8.45-1.fc43.9 Β· BSD-3-Clause
- fedora 43: pcre-devel 8.45-1.fc43.9 Β· BSD-3-Clause
- fedora 44: pcre-devel 8.45-1.fc43.9 Β· BSD-3-Clause
- fedora 44: pcre-devel 8.45-1.fc43.9 Β· BSD-3-Clause
- nixos 26.05: pcre 8.45
- nixos 26.05: pcre-cpp 8.45
- opensuse-leap 16.0: pcre-devel 8.45-160000.2.2 Β· BSD-3-Clause
- opensuse-leap 16.0: pcre-devel 8.45-160000.2.2 Β· BSD-3-Clause
- opensuse-leap 16.0: pcre-devel 8.45-160000.2.2 Β· BSD-3-Clause
- opensuse-leap 16.0: pcre-devel 8.45-160000.2.2 Β· BSD-3-Clause
- ubuntu jammy: libpcre3-dev 2:8.39-13build5
- ubuntu jammy: libpcre3-dev 2:8.39-13ubuntu0.22.04.1
- ubuntu noble: libpcre3-dev 2:8.39-15build1
- ubuntu questing: libpcre3-dev 2:8.39-15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms