PCRE_DFA_EXEC(3)
π PCRE_DFA_EXEC π
okay bestie, gather round, because this is the PCRE_DFA_EXEC(3) page from the Library Functions Manual and it's lowkey one of the most underrated lil functions in the whole PCRE squad. it's the alt-girl of matching algorithms: not Perl-compatible, scans your subject string exactly once, and does NOT play by the usual rules. iconic behaviour honestly. β¨
πΈ NAME πΈ
PCRE β Perl-compatible regular expressions. yes that's the whole name section, she's brief and mysterious, we love a minimal queen. π
β¨ SYNOPSIS β¨
#include <pcre.h>
int pcre_dfa_exec(const pcre *code, const pcre_extra *extra,
const char *subject, int length, int startoffset,
int options, int *ovector, int ovecsize,
int *workspace, int wscount);
int pcre16_dfa_exec(const pcre16 *code, const pcre16_extra *extra,
PCRE_SPTR16 subject, int length, int startoffset,
int options, int *ovector, int ovecsize,
int *workspace, int wscount);
int pcre32_dfa_exec(const pcre32 *code, const pcre32_extra *extra,
PCRE_SPTR32 subject, int length, int startoffset,
int options, int *ovector, int ovecsize,
int *workspace, int wscount);
three flavours, one vibe: 8-bit, 16-bit and 32-bit, all living their best lives. π«Ά
π¦ DESCRIPTION π¦
so what does this actually do, bestie? it matches a compiled regular expression against a given subject string, but using an alternative matching algorithm that scans the subject string just once β and heads up, this one is not Perl-compatible. no cap. the main, Perl-compatible, matching function is pcre[16|32]_exec(), so if you want the classic behaviour, go knock on her door instead. πͺ
here's the full cast of arguments, and yes every single one matters:
codeβ points to the compiled patternextraβ points to an associatedpcre[16|32]_extrastructure, or isNULLsubjectβ points to the subject stringlengthβ length of the subject stringstartoffsetβ offset in the subject at which to start matchingoptionsβ option bitsovectorβ points to a vector of ints for result offsetsovecsizeβ number of elements in the vectorworkspaceβ points to a vector of ints used as working spacewscountβ number of elements in the vector
the units for length and startoffset are bytes for pcre_exec(), 16-bit data items for pcre16_exec(), and 32-bit items for pcre32_exec(). write that down, it will absolutely come up. π
π the options, in all their glory π
and now the moment you've been waiting for β the option bits, listed in full, no skipping, no summarising, we're doing ALL of them:
PCRE_ANCHOREDβ match only at the first positionPCRE_BSR_ANYCRLFβ\Rmatches only CR, LF, or CRLFPCRE_BSR_UNICODEβ\Rmatches all Unicode line endingsPCRE_NEWLINE_ANYβ recognize any Unicode newline sequencePCRE_NEWLINE_ANYCRLFβ recognize CR, LF, & CRLF as newline sequencesPCRE_NEWLINE_CRβ recognize CR as the only newline sequencePCRE_NEWLINE_CRLFβ recognize CRLF as the only newline sequencePCRE_NEWLINE_LFβ recognize LF as the only newline sequencePCRE_NOTBOLβ subject is not the beginning of a linePCRE_NOTEOLβ subject is not the end of a linePCRE_NOTEMPTYβ an empty string is not a valid matchPCRE_NOTEMPTY_ATSTARTβ an empty string at the start of the subject is not a valid matchPCRE_NO_START_OPTIMIZEβ do not do "start-match" optimizationsPCRE_NO_UTF16_CHECKβ do not check the subject for UTF-16 validity (only relevant ifPCRE_UTF16was set at compile time)PCRE_NO_UTF32_CHECKβ do not check the subject for UTF-32 validity (only relevant ifPCRE_UTF32was set at compile time)PCRE_NO_UTF8_CHECKβ do not check the subject for UTF-8 validity (only relevant ifPCRE_UTF8was set at compile time)PCRE_PARTIAL/PCRE_PARTIAL_SOFTβ returnPCRE_ERROR_PARTIALfor a partial match if no full matches are found (these two share a description in the original, they're a package deal, besties π)PCRE_PARTIAL_HARDβ returnPCRE_ERROR_PARTIALfor a partial match even if there is a full match as wellPCRE_DFA_SHORTESTβ return only the shortest matchPCRE_DFA_RESTARTβ restart after a partial match
π the restrictions (yes, there are restrictions) π
there are restrictions on what may appear in a pattern when using this matching function. bestie, this is not a drill. details are given in the pcrematching documentation. π
and for details of partial matching, see the pcrepartial page. go read them, i'll wait. π
π§ the pcre[16|32]_extra structure π§
a pcre[16|32]_extra structure contains the following fields:
flagsβ bits indicating which fields are setstudy_dataβ opaque data frompcre[16|32]_study()match_limitβ limit on internal resource usematch_limit_recursionβ limit on internal recursion depthcallout_dataβ opaque data passed back to calloutstablesβ points to character tables or isNULLmarkβ for passing back a*MARKpointerexecutable_jitβ opaque data from JIT compilation
the flag bits are PCRE_EXTRA_STUDY_DATA, PCRE_EXTRA_MATCH_LIMIT, PCRE_EXTRA_MATCH_LIMIT_RECURSION, PCRE_EXTRA_CALLOUT_DATA, PCRE_EXTRA_TABLES, PCRE_EXTRA_MARK and PCRE_EXTRA_EXECUTABLE_JIT.
and here's the important tea π΅: for this matching function, thematch_limitandmatch_limit_recursionfields are not used, and must not be set. thePCRE_EXTRA_EXECUTABLE_JITflag and the corresponding variable are ignored. so don't come for them, they're simply not invited to this party. π
π SEE ALSO (in spirit, because the original just says this inline) π
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. both absolute reads, honestly. π
and that's the whole thing, bestie β you ate that. π«Άβ¨
this page is brought to you by PCRE 8.33, dated 12 May 2013. yes, she's vintage, she's classic, she's still slaying. mwah. π π
π¦ 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