PCRE_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 bestiesubjectβ the subject string that has already been successfully matched (key word: successfully, don't play games π)ovectorβ the offset vector thatpcre[16|32]_exec()usedstringcountβ the value thatpcre[16|32]_exec()returnedstringnameβ the name of the substring you want, bestiestringptrβ 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:
- the length of the extracted substring β¨
PCRE_ERROR_NOMEMORYif it couldn't get enough memory πPCRE_ERROR_NOSUBSTRINGif 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 π π
π¦ where this page comes from
- alpine 3.22: pcre-doc 8.45-r4 Β· BSD-3-Clause
- alpine 3.23: pcre-doc 8.45-r4 Β· BSD-3-Clause
- alpine 3.24: pcre-doc 8.45-r4 Β· BSD-3-Clause
- arch rolling: pcre 8.45-5 Β· BSD
- centos-stream 9: pcre-devel 8.44-4.el9 Β· BSD
- centos-stream 9: pcre-devel 8.44-4.el9 Β· BSD
- debian bookworm: libpcre3-dev 2:8.39-15
- fedora 43: pcre-devel 8.45-1.fc43.9 Β· BSD-3-Clause
- fedora 43: pcre-devel 8.45-1.fc43.9 Β· BSD-3-Clause
- fedora 44: pcre-devel 8.45-1.fc43.9 Β· BSD-3-Clause
- fedora 44: pcre-devel 8.45-1.fc43.9 Β· BSD-3-Clause
- nixos 26.05: pcre 8.45
- nixos 26.05: pcre-cpp 8.45
- opensuse-leap 16.0: pcre-devel 8.45-160000.2.2 Β· BSD-3-Clause
- opensuse-leap 16.0: pcre-devel 8.45-160000.2.2 Β· BSD-3-Clause
- opensuse-leap 16.0: pcre-devel 8.45-160000.2.2 Β· BSD-3-Clause
- opensuse-leap 16.0: pcre-devel 8.45-160000.2.2 Β· BSD-3-Clause
- ubuntu jammy: libpcre3-dev 2:8.39-13build5
- ubuntu jammy: libpcre3-dev 2:8.39-13ubuntu0.22.04.1
- ubuntu noble: libpcre3-dev 2:8.39-15build1
- ubuntu questing: libpcre3-dev 2:8.39-15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms