PCRE2_SUBS...T_BYNUMBER(3)

πŸ’– NAME πŸ’–

PCRE2 β€” Perl-compatible regular expressions (revised API), bestie!! Fr fr, that's the whole vibe. ✨


πŸŽ€ SYNOPSIS πŸŽ€

Like, here's the whole thing you gotta pull in first, no cap:

#include <pcre2.h>

int pcre2_substring_get_bynumber(pcre2_match_data *match_data,
  uint32_t number, PCRE2_UCHAR **bufferptr, PCRE2_SIZE *bufflen);

Periodt. That's the function signature, character for character, don't @ me. πŸ’…


🌸 DESCRIPTION 🌸

Okay so picture this: this is a convenience function for extracting a captured substring by number into newly acquired memory. It's giving "I got you, bestie" energy β€” it does the allocation dance so you don't have to. 🫢

The arguments are, in order:

  • match_data β€” the match data for the match πŸ‘‘
  • number β€” the number of the required substring (yes, by number, iykyk)
  • bufferptr β€” where to put the string pointer
  • bufflen β€” where to put the string length

The memory where the substring gets placed? It's obtained by calling the same memory allocation function that was used for the match data block. Consistency icon. ✨

πŸ’‘ When you're done with it, the convenience function pcre2_substring_free() can be used to free it β€” please actually free it, bestie, your process deserves better. 🧚

The yield of the function is zero for success, or one of these error numbers (write these down, they're on the exam):

  • PCRE2_ERROR_NOSUBSTRING β€” there are no groups of that number 😭
  • PCRE2_ERROR_UNAVAILBLE β€” the ovector was too small for that group πŸ™ˆ (that spelling is literally what the page says, copying it exactly, not my typo, I promise)
  • PCRE2_ERROR_UNSET β€” the group did not participate in the match πŸ’€
  • PCRE2_ERROR_NOMEMORY β€” memory could not be obtained πŸ“

πŸ¦‹ SEE ALSO (but make it cute) πŸ¦‹

There's a complete description of the PCRE2 native API in the pcre2api page, and a description of the POSIX API in the pcre2posix page. Go read those, they ate. πŸ”₯


cute sign-off πŸŽ€ β€” this little love letter comes from the PCRE2 10.47 manual, dated 13 December 2014. Slay, archive her, she's iconic. πŸŒˆπŸ’œ

πŸ“¦ where this page comes from