PCRE_COPY_SUBSTRING(3)

πŸ’– PCRE_COPY_SUBSTRING πŸ’–

okay bestie, so this one lives in the Library Functions Manual, and it's page PCRE_COPY_SUBSTRING(3) β€” yes it's giving "library functions" energy, we love that for it. sit down, hydrate, we're doing substring extraction πŸ“


✨ NAME ✨

PCRE β€” Perl-compatible regular expressions. that's the whole vibe. no cap. πŸ’…


🌸 SYNOPSIS 🌸

like, here's the actual shape of it, don't @ me, this is verbatim:

#include <pcre.h>

int pcre_copy_substring(const char *subject, int *ovector,
     int stringcount, int stringnumber, char *buffer,
     int buffersize);

int pcre16_copy_substring(PCRE_SPTR16 subject, int *ovector,
     int stringcount, int stringnumber, PCRE_UCHAR16 *buffer,
     int buffersize);

int pcre32_copy_substring(PCRE_SPTR32 subject, int *ovector,
     int stringcount, int stringnumber, PCRE_UCHAR32 *buffer,
     int buffersize);

three versions, three widths, one iconique little function. 8-bit, 16-bit, 32-bit β€” pick your fighter πŸ¦‹


πŸŽ€ DESCRIPTION πŸŽ€

so basically, this is a convenience function for extracting a captured substring into a given buffer. it's the "just put the thing in the buffer already" function. the way it just does that? obsessed. ✨

the arguments are, and I'm gonna be so real with you:

  • subject β€” subject that has been successfully matched. like, the string you already ran through and it hit. 🎯
  • ovector β€” the offset vector that pcre[16|32]_exec() used. that's the receipts. 🧾
  • stringcount β€” value returned by pcre[16|32]_exec(). yes, you gotta hand it back. it said what it said.
  • stringnumber β€” number of the required substring. which one you want, bestie. be specific.
  • buffer β€” buffer to receive the string. it's the lil container, the tote bag of it all πŸ‘œ
  • buffersize β€” size of buffer. and you better get this right, I'm just saying πŸ™ˆ

⭐ the yield, aka what you get back ⭐

  • the length of the string β€” slay, that's your win πŸ’–
  • PCRE_ERROR_NOMEMORY β€” if the buffer was too small. tragic. the buffer simply could not. 😭
  • PCRE_ERROR_NOSUBSTRING β€” if the string number is invalid. you asked for a substring that does not exist, bestie. it's giving void. πŸ’€
fr fr: if your buffer is too small you get PCRE_ERROR_NOMEMORY, not a truncated vibe. size it correctly or perish (gently). 🫢

🌈 where to go next 🌈

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, iykyk πŸ“šβœ¨


and that's the whole page, bestie. this was PCRE 8.30, dated 24 June 2012 β€” yeah she's an elder but she still ate. mwah πŸ’…πŸ‘‘