pcre_get.c


Function pcre_get_stringnumber

Find number for named string

This function is used by the two extraction functions below, as well as being generally available.

Synopsis

Prototype
int pcre_get_stringnumber (
      const pcre* code,
      const char* stringname
);

TypeNameRead/WriteDescription
const pcre*codeInputthe compiled regex
const char*stringnameInputthe name whose number is required
int RETURNthe number of the named parentheses, or a negative number (PCRE_ERROR_NOSUBSTRING) if not found

Input
code:(Input)the compiled regex
stringname:(Input)the name whose number is required
Returns
int:the number of the named parentheses, or a negative number (PCRE_ERROR_NOSUBSTRING) if not found

Description

Find number for named string

This function is used by the two extraction functions below, as well as being generally available.

Usage

See source code

Example

In preparation

Errors

See source code

Dependencies

See source code

See Also

See other functions in this section

Availability

In release 5.0.0

Function pcre_copy_substring

Copy captured string to given buffer

This function copies a single captured substring into a given buffer. Note that we use memcpy() rather than strncpy() in case there are binary zeros in the string.

Synopsis

Prototype
int pcre_copy_substring (
      const char* subject,
      const int* ovector,
      int stringcount,
      int stringnumber,
      char* buffer,
      int size
);

TypeNameRead/WriteDescription
const char*subjectInputthe subject string that was matched
const int*ovectorInputpointer to the offsets table
intstringcountInputthe number of substrings that were captured (i.e. the yield of the pcre_exec call, unless that was zero, in which case it should be 1/3 of the offset table size)
intstringnumberInputthe number of the required substring
char*bufferOutputwhere to put the substring
intsizeInputthe size of the buffer
int RETURNif successful: the length of the copied string, not including the zero that is put on the end; can be zero if not successful: PCRE_ERROR_NOMEMORY (-6) buffer too small PCRE_ERROR_NOSUBSTRING (-7) no such captured substring

Input
subject:(Input)the subject string that was matched
ovector:(Input)pointer to the offsets table
stringcount:(Input)the number of substrings that were captured (i.e. the yield of the pcre_exec call, unless that was zero, in which case it should be 1/3 of the offset table size)
stringnumber:(Input)the number of the required substring
size:(Input)the size of the buffer
Output
buffer:(Output)where to put the substring
Returns
int:if successful: the length of the copied string, not including the zero that is put on the end; can be zero if not successful: PCRE_ERROR_NOMEMORY (-6) buffer too small PCRE_ERROR_NOSUBSTRING (-7) no such captured substring

Description

Copy captured string to given buffer

This function copies a single captured substring into a given buffer. Note that we use memcpy() rather than strncpy() in case there are binary zeros in the string.

Usage

See source code

Example

In preparation

Errors

See source code

Dependencies

See source code

See Also

See other functions in this section

Availability

In release 5.0.0

Function pcre_copy_named_substring

Copy named captured string to given buffer

This function copies a single captured substring into a given buffer, identifying it by name.

Synopsis

Prototype
int pcre_copy_named_substring (
      const pcre* code,
      const char* subject,
      const int* ovector,
      int stringcount,
      const char* stringname,
      char* buffer,
      int size
);

TypeNameRead/WriteDescription
const pcre*codeInputthe compiled regex
const char*subjectInputthe subject string that was matched
const int*ovectorInputpointer to the offsets table
intstringcountInputthe number of substrings that were captured (i.e. the yield of the pcre_exec call, unless that was zero, in which case it should be 1/3 of the offset table size)
const char*stringnameInputthe name of the required substring
char*bufferOutputwhere to put the substring
intsizeInputthe size of the buffer
int RETURNif successful: the length of the copied string, not including the zero that is put on the end; can be zero if not successful: PCRE_ERROR_NOMEMORY (-6) buffer too small PCRE_ERROR_NOSUBSTRING (-7) no such captured substring

Input
code:(Input)the compiled regex
subject:(Input)the subject string that was matched
ovector:(Input)pointer to the offsets table
stringcount:(Input)the number of substrings that were captured (i.e. the yield of the pcre_exec call, unless that was zero, in which case it should be 1/3 of the offset table size)
stringname:(Input)the name of the required substring
size:(Input)the size of the buffer
Output
buffer:(Output)where to put the substring
Returns
int:if successful: the length of the copied string, not including the zero that is put on the end; can be zero if not successful: PCRE_ERROR_NOMEMORY (-6) buffer too small PCRE_ERROR_NOSUBSTRING (-7) no such captured substring

Description

Copy named captured string to given buffer

This function copies a single captured substring into a given buffer, identifying it by name.

Usage

See source code

Example

In preparation

Errors

See source code

Dependencies

See source code

See Also

See other functions in this section

Availability

In release 5.0.0

Function pcre_get_substring_list

Copy all captured strings to new store

This function gets one chunk of store and builds a list of pointers and all of the captured substrings in it. A NULL pointer is put on the end of the list.

Synopsis

Prototype
int pcre_get_substring_list (
      const char* subject,
      const int* ovector,
      int stringcount,
      const char*** listptr
);

TypeNameRead/WriteDescription
const char*subjectInputthe subject string that was matched
const int*ovectorOutputpointer to the offsets table
intstringcountInputthe number of substrings that were captured (i.e. the yield of the pcre_exec call, unless that was zero, in which case it should be 1/3 of the offset table size)
const char***listptrInputset to point to the list of pointers
int RETURNif successful: 0 if not successful: PCRE_ERROR_NOMEMORY (-6) failed to get store

Input
subject:(Input)the subject string that was matched
stringcount:(Input)the number of substrings that were captured (i.e. the yield of the pcre_exec call, unless that was zero, in which case it should be 1/3 of the offset table size)
listptr:(Input)set to point to the list of pointers
Output
ovector:(Output)pointer to the offsets table
Returns
int:if successful: 0 if not successful: PCRE_ERROR_NOMEMORY (-6) failed to get store

Description

Copy all captured strings to new store

This function gets one chunk of store and builds a list of pointers and all of the captured substrings in it. A NULL pointer is put on the end of the list.

Usage

See source code

Example

In preparation

Errors

See source code

Dependencies

See source code

See Also

See other functions in this section

Availability

In release 5.0.0

Function pcre_free_substring_list

Free store obtained by get_substring_list

This function exists for the benefit of people calling PCRE from non-C programs that can call its functions, but not free() or (pcre_free)() directly.

Synopsis

Prototype
void pcre_free_substring_list (
      const char** pointer
);

TypeNameRead/WriteDescription
const char**pointerInputthe result of a previous pcre_get_substring_list()
void RETURN

Input
pointer:(Input)the result of a previous pcre_get_substring_list()
Returns
void:No return value

Description

Free store obtained by get_substring_list

This function exists for the benefit of people calling PCRE from non-C programs that can call its functions, but not free() or (pcre_free)() directly.

Usage

See source code

Example

In preparation

Errors

See source code

Dependencies

See source code

See Also

See other functions in this section

Availability

In release 5.0.0

Function pcre_get_substring

Copy captured string to new store

This function copies a single captured substring into a piece of new store

Synopsis

Prototype
int pcre_get_substring (
      const char* subject,
      const int* ovector,
      int stringcount,
      int stringnumber,
      const char** stringptr
);

TypeNameRead/WriteDescription
const char*subjectInputthe subject string that was matched
const int*ovectorInputpointer to the offsets table
intstringcountInputthe number of substrings that were captured (i.e. the yield of the pcre_exec call, unless that was zero, in which case it should be 1/3 of the offset table size)
intstringnumberInputthe number of the required substring
const char**stringptrOutputwhere to put a pointer to the substring
int RETURNif successful: the length of the string, not including the zero that is put on the end; can be zero if not successful: PCRE_ERROR_NOMEMORY (-6) failed to get store PCRE_ERROR_NOSUBSTRING (-7) substring not present

Input
subject:(Input)the subject string that was matched
ovector:(Input)pointer to the offsets table
stringcount:(Input)the number of substrings that were captured (i.e. the yield of the pcre_exec call, unless that was zero, in which case it should be 1/3 of the offset table size)
stringnumber:(Input)the number of the required substring
Output
stringptr:(Output)where to put a pointer to the substring
Returns
int:if successful: the length of the string, not including the zero that is put on the end; can be zero if not successful: PCRE_ERROR_NOMEMORY (-6) failed to get store PCRE_ERROR_NOSUBSTRING (-7) substring not present

Description

Copy captured string to new store

This function copies a single captured substring into a piece of new store

Usage

See source code

Example

In preparation

Errors

See source code

Dependencies

See source code

See Also

See other functions in this section

Availability

In release 5.0.0

Function pcre_get_named_substring

Copy named captured string to new store

This function copies a single captured substring, identified by name, into new store.

Synopsis

Prototype
int pcre_get_named_substring (
      const pcre* code,
      const char* subject,
      const int* ovector,
      int stringcount,
      const char* stringname,
      const char** stringptr
);

TypeNameRead/WriteDescription
const pcre*codeInputthe compiled regex
const char*subjectInputthe subject string that was matched
const int*ovectorInputpointer to the offsets table
intstringcountInputthe number of substrings that were captured (i.e. the yield of the pcre_exec call, unless that was zero, in which case it should be 1/3 of the offset table size)
const char*stringnameInputthe name of the required substring
const char**stringptrOutputwhere to put the pointer
int RETURNif successful: the length of the copied string, not including the zero that is put on the end; can be zero if not successful: PCRE_ERROR_NOMEMORY (-6) couldn't get memory PCRE_ERROR_NOSUBSTRING (-7) no such captured substring

Input
code:(Input)the compiled regex
subject:(Input)the subject string that was matched
ovector:(Input)pointer to the offsets table
stringcount:(Input)the number of substrings that were captured (i.e. the yield of the pcre_exec call, unless that was zero, in which case it should be 1/3 of the offset table size)
stringname:(Input)the name of the required substring
Output
stringptr:(Output)where to put the pointer
Returns
int:if successful: the length of the copied string, not including the zero that is put on the end; can be zero if not successful: PCRE_ERROR_NOMEMORY (-6) couldn't get memory PCRE_ERROR_NOSUBSTRING (-7) no such captured substring

Description

Copy named captured string to new store

This function copies a single captured substring, identified by name, into new store.

Usage

See source code

Example

In preparation

Errors

See source code

Dependencies

See source code

See Also

See other functions in this section

Availability

In release 5.0.0

Function pcre_free_substring

Free store obtained by get_substring

This function exists for the benefit of people calling PCRE from non-C programs that can call its functions, but not free() or (pcre_free)() directly.

Synopsis

Prototype
void pcre_free_substring (
      const char** pointer
);

TypeNameRead/WriteDescription
const char**pointerDeletethe result of a previous pcre_get_substring()
void RETURN

Output
pointer:(Delete)the result of a previous pcre_get_substring()
Returns
void:No return value

Description

Free store obtained by get_substring

This function exists for the benefit of people calling PCRE from non-C programs that can call its functions, but not free() or (pcre_free)() directly.

Usage

See source code

Example

In preparation

Errors

See source code

Dependencies

See source code

See Also

See other functions in this section

Availability

In release 5.0.0