---
name: "pcre_get_substring"
section: "3"
platform: "linux"
package: "pcre"
version: "8.45-5"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/pcre_get_substring"
---

# pcre\_get\_substring(3)

Perl-compatible regular expressions

## NAME

PCRE - 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

This is a convenience function for extracting a captured substring. The arguments are:

  *subject*       Subject that has been successfully matched\
   *ovector*       Offset vector that **pcre\[16\|32\]\_exec()** used\
   *stringcount*   Value returned by **pcre\[16\|32\]\_exec()**\
   *stringnumber*  Number of the required substring\
   *stringptr*     Where to put the string pointer

The memory in which the substring is placed is obtained by calling **pcre\[16\|32\]\_malloc()**. The convenience function **pcre\[16\|32\]\_free\_substring()** can be used to free it when it is no longer needed. The yield of the function is the length of the substring, PCRE\_ERROR\_NOMEMORY if sufficient memory could not be obtained, or PCRE\_ERROR\_NOSUBSTRING if the string number is invalid.

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.
