PCRE16_GET_NAMED_SUBSTRING(3)

πŸ’– NAME πŸ’–

okay so this is pcre16_get_named_substring(3) from the Library Functions Manual bestie, and what it is, is PCRE β€” that's Perl-compatible regular expressions πŸ’…


✨ SYNOPSIS ✨

here's the vibe, three flavors of the exact same energy 🫢

#include <pcre.h>

int pcre_get_named_substring(const pcre *code,
     const char *subject, int *ovector,
     int stringcount, const char *stringname,
     const char **stringptr);

int pcre16_get_named_substring(const pcre16 *code,
     PCRE_SPTR16 subject, int *ovector,
     int stringcount, PCRE_SPTR16 stringname,
     PCRE_SPTR16 *stringptr);

int pcre32_get_named_substring(const pcre32 *code,
     PCRE_SPTR32 subject, int *ovector,
     int stringcount, PCRE_SPTR32 stringname,
     PCRE_SPTR32 *stringptr);

🌸 DESCRIPTION 🌸

so like. this is a convenience function, and it's literally just here to hand you a captured substring by its name instead of making you count capture groups like a peasant. it's giving "i know what i named it, just give it to me" 😭✨

here's what you're feeding it:

  • code β€” your compiled pattern, the whole blueprint bestie
  • subject β€” the subject string that has already been successfully matched (key word: successfully, don't play games πŸ™ˆ)
  • ovector β€” the offset vector that pcre[16|32]_exec() used
  • stringcount β€” the value that pcre[16|32]_exec() returned
  • stringname β€” the name of the substring you want, bestie
  • stringptr β€” where to put the string pointer πŸ‘‘

the memory where that substring gets placed? it's obtained by calling pcre[16|32]_malloc() πŸ’– so it's yours, you own it, and when you don't need it anymore you use the convenience function pcre[16|32]_free_substring() to let it go. free your friends, periodt πŸŽ€

the yield of the function β€” what it gives back to you β€” is one of three things:

  1. the length of the extracted substring ✨
  2. PCRE_ERROR_NOMEMORY if it couldn't get enough memory 😭
  3. PCRE_ERROR_NOSUBSTRING if the string name is invalid πŸ’€
ngl if you get PCRE_ERROR_NOSUBSTRING that name does not exist in your pattern. that's on the name, not on you, but still. check 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. go read those if you want the full lore, iykyk πŸ“šπŸ’œ


okay that's the whole thing bestie, slay, go extract some substrings πŸ¦‹πŸŒΈ

this was PCRE 8.30, dated 24 June 2012 β€” iconic, vintage, still serving πŸ’…πŸ‘‘