PCRE_GET_STRINGNUMBER(3)

✨ PCRE_GET_STRINGNUMBER ✨

okay so bestie, welcome to the PCRE manual β€” that's Perl-compatible regular expressions, and this page right here is about one lil function that does one lil job. it's giving "small but mighty" energy. πŸ’–


🌸 NAME 🌸

PCRE β€” Perl-compatible regular expressions. that's it, that's the name, no notes. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

so here's how you call it. first you gotta include the header:

#include <pcre.h>

and then there's not one, not two, but three versions of this function β€” one for each width, because PCRE said "why pick a character size when you can have all of them" ✨

int pcre_get_stringnumber(const pcre *code,
     const char *name);

int pcre16_get_stringnumber(const pcre16 *code,
     PCRE_SPTR16 name);

int pcre32_get_stringnumber(const pcre32 *code,
     PCRE_SPTR32 name);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so the tea β˜•: this is a convenience function, which is just fancy speak for "we made this easy for you, you're welcome." what it does is it finds the number of a named substring capturing parenthesis inside a compiled pattern. basically: you gave a capture group a cute lil name, and now you wanna know what index it's sitting at. and this function tells you. 🫢

here's the two arguments it takes, laid out all pretty:

  • code β€” the compiled regular expression. yes, the whole thing, already compiled. πŸ’–
  • name β€” the name whose number is required. like, you hand over the name, it hands back the digits. iconic behavior fr fr.

🌈 what you get back 🌈

the yield of the function is the number of the parenthesis if the name is found. and if it's not found? you get PCRE_ERROR_NOSUBSTRING instead. so like, bestie, check your return value, don't just assume. 😭

⚠️ important caveat alert, no cap: when duplicate names are allowed (PCRE_DUPNAMES is set), it is not defined which of the numbers is returned by pcre[16|32]_get_stringnumber(). that's right β€” undefined. it's a vibe, not a promise. πŸ™ˆ

and if you do need the whole squad, you can obtain the complete list by calling pcre[16|32]_get_stringtable_entries(). that one's your group-chat roster. πŸ‘‘


πŸ’œ where to go next πŸ’œ

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, they ate. πŸ”₯


that's the whole page bestie, you're officially un-stuck πŸ’…

sign-off: this was PCRE 8.30, dated 24 June 2012 β€” and it lives in the Library Functions Manual. mwah. πŸŽ€πŸ’–βœ¨