PCRE_EXEC(3)

πŸ’– NAME πŸ’–

PCRE β€” Perl-compatible regular expressions ✨ (and bestie, that's the whole vibe of the pcre_exec family of functions, iykyk)


✨ SYNOPSIS ✨

okay so first you gotta pull in the header, like always:

#include <pcre.h>

and then the three icons themselves πŸ’…:

int pcre_jit_exec(const pcre *code, const pcre_extra *extra,
     const char *subject, int length, int startoffset,
     int options, int *ovector, int ovecsize,
     pcre_jit_stack *jstack);

int pcre16_jit_exec(const pcre16 *code, const pcre16_extra *extra,
     PCRE_SPTR16 subject, int length, int startoffset,
     int options, int *ovector, int ovecsize,
     pcre_jit_stack *jstack);

int pcre32_jit_exec(const pcre32 *code, const pcre32_extra *extra,
     PCRE_SPTR32 subject, int length, int startoffset,
     int options, int *ovector, int ovecsize,
     pcre_jit_stack *jstack);

three bit-widths, one queen energy πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so picture this: you've got a compiled regular expression that's already been successfully studied with one of the JIT options, and now you wanna match it against a subject string. That's literally what this does. It uses a matching algorithm that's similar to Perl's, and it's the "fast path" interface to JIT β€” which lowkey means it bypasses some of the sanity checks that pcre_exec() applies. 🫣 (fr fr, the checks are just not there, bestie.)

It returns offsets to captured substrings. Its arguments are:

  • code β€” Points to the compiled pattern
  • extra β€” Points to an associated pcre[16|32]_extra structure, or is NULL
  • subject β€” Points to the subject string
  • length β€” Length of the subject string, in bytes
  • startoffset β€” Offset in bytes in the subject at which to start matching
  • options β€” Option bits
  • ovector β€” Points to a vector of ints for result offsets
  • ovecsize β€” Number of elements in the vector (a multiple of 3)
  • jstack β€” Pointer to a JIT stack

🌸 the allowed options 🌸

  • PCRE_NOTBOL β€” Subject string is not the beginning of a line
  • PCRE_NOTEOL β€” Subject string is not the end of a line
  • PCRE_NOTEMPTY β€” An empty string is not a valid match
  • PCRE_NOTEMPTY_ATSTART β€” An empty string at the start of the subject is not a valid match
  • PCRE_NO_UTF16_CHECK β€” Do not check the subject for UTF-16 validity (only relevant if PCRE_UTF16 was set at compile time)
  • PCRE_NO_UTF32_CHECK β€” Do not check the subject for UTF-32 validity (only relevant if PCRE_UTF32 was set at compile time)
  • PCRE_NO_UTF8_CHECK β€” Do not check the subject for UTF-8 validity (only relevant if PCRE_UTF8 was set at compile time)
  • PCRE_PARTIAL β€” ) Return PCRE_ERROR_PARTIAL for a partial match if no full matches are found
  • PCRE_PARTIAL_SOFT β€” ) Return PCRE_ERROR_PARTIAL for a partial match if no full matches are found
  • PCRE_PARTIAL_HARD β€” Return PCRE_ERROR_PARTIAL for a partial match if that is found before a full match
πŸ‘€ note that PCRE_PARTIAL and PCRE_PARTIAL_SOFT are grouped together in the original with those little ) markers, and PCRE_PARTIAL_HARD is the one doing its own thing.

However β€” and this is the plot twist πŸŽ€ β€” the PCRE_NO_UTF[8|16|32]_CHECK options have no effect, because this check is never applied. So don't be out here thinking they're gonna do something, bestie, they're just chilling there. For details of partial matching, see the pcrepartial page.


πŸ’œ the pcre_extra structure πŸ’œ

A pcre_extra structure contains the following fields:

  • flags β€” Bits indicating which fields are set
  • study_data β€” Opaque data from pcre[16|32]_study()
  • match_limit β€” Limit on internal resource use
  • match_limit_recursion β€” Limit on internal recursion depth
  • callout_data β€” Opaque data passed back to callouts
  • tables β€” Points to character tables or is NULL
  • mark β€” For passing back a *MARK pointer
  • executable_jit β€” Opaque data from JIT compilation

🌈 the flag bits 🌈

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. ✨


There is a complete description of the PCRE native API in the pcreapi page and a description of the JIT API in the pcrejit page. Go read those, they ate. πŸ”₯


and that's the whole page, bestie!! 🫢 this was PCRE 8.30, dated 31 October 2012, from the Library Functions Manual β€” slay, no cap, periodt πŸ’…βœ¨