PCRE_GET_SUBSTRING(3)
β¨ PCRE_GET_SUBSTRING β¨
okay bestie, welcome to PCRE_GET_SUBSTRING(3) π this one lives in the Library Functions Manual and it's the little glow-up of the PCRE family β aka Perl-compatible regular expressions π¦
πΈ SYNOPSIS πΈ
#include <pcre.h>
int pcre_get_substring(const char *subject, int *ovector,
int stringcount, int stringnumber,
const char **stringptr);
int pcre16_get_substring(PCRE_SPTR16 subject, int *ovector,
int stringcount, int stringnumber,
PCRE_SPTR16 *stringptr);
int pcre32_get_substring(PCRE_SPTR32 subject, int *ovector,
int stringcount, int stringnumber,
PCRE_SPTR32 *stringptr);
π DESCRIPTION π
so this is a convenience function for extracting a captured substring π like, you already matched, you already got your capture, and now you just want the actual text out of it. no cap, that's the whole vibe.
the arguments are, in order:
subjectβ the subject that has been successfully matched β¨ovectorβ the offset vector thatpcre[16|32]_exec()used πstringcountβ the value returned bypcre[16|32]_exec()πstringnumberβ the number of the required substring πstringptrβ where to put the string pointer π
the memory the substring gets placed in? that's obtained by calling pcre[16|32]_malloc() π«Ά and listen, when you're done with it, the convenience function pcre[16|32]_free_substring() can be used to free it. free your girl, she deserves it π
the yield of the function β the return, the moment of truth β is the length of the substring β OR PCRE_ERROR_NOMEMORY if sufficient memory could not be obtained π OR PCRE_ERROR_NOSUBSTRING if the string number is invalid π
fr fr: invalid string number gets youPCRE_ERROR_NOSUBSTRING, and not having enough memory gets youPCRE_ERROR_NOMEMORY. those are the two ways this can say "no bestie" π
also 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 π
mwah π that's the page!! this one's from PCRE 8.30, dated 24 June 2012, and the manual name is PCRE_GET_SUBSTRING(3) β slay, go capture something iconic bestie β¨π
π¦ 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