Pcre function to parse _c language in detail

Source: Internet
Author: User
Tags error code null null

Pcre is an NFA regular engine, or it cannot provide regular syntax functionality that is completely consistent with Perl. But it also realizes the DFA, just satisfies the mathematical sense of the regular.

1. Pcre_compile

Prototype:
#include <pcre.h>
Pcre *pcre_compile (const char *pattern, int options, const char **errptr, int *erroffset, const unsigned char *tableptr);

Function: Compiles a regular expression into an internal representation that accelerates the match when matching multiple strings. The same as the Pcre_compile2 function is only missing a parameter errorcodeptr.

Parameters:
Pattern Regular Expressions
Option 0, or other parameter options
ERRPTR error message
Erroffset Error Location
Tableptr a pointer to a character array, which can be set to NULL NULL

Example:

Copy Code code as follows:

L1720 re = pcre_compile ((char *) p, options, &error, &erroroffset, tables);

2. Pcre_compile2

Prototype:
#include <pcre.h>
Pcre *pcre_compile2 (const char *pattern, int options, int *errorcodeptr, const char **errptr, int *erroffset, const unsign Ed Char *tableptr);

Function: Compiles a regular expression into an internal representation that accelerates the match when matching multiple strings. The same as the Pcre_compile function is just one more parameter errorcodeptr.

Parameters:
Pattern Regular Expressions
Option 0, or other parameter options
ERRORCODEPTR Store error code
ERRPTR error message
Erroffset Error Location
Tableptr a pointer to a character array, which can be set to NULL NULL

3. Pcre_config

Prototype:
#include <pcre.h>
int pcre_config (int what, void *where);

Function: Queries the option information used in the current Pcre version.

Parameters:
What option name
Where the result is stored

Example:

Line1312 (void) pcre_config (Pcre_config_posix_malloc_threshold, &RC);

4. pcre_copy_named_substring

Prototype:
#include <pcre.h>
int pcre_copy_named_substring (const pcre *code, const char *subject, int *ovector, int stringcount, const char *stringname , char *buffer, int buffersize);

Function: Gets the captured string by name.

Parameters:
Pattern of code Success matching
Subject matching string
Offset vector used by ovectorpcre_exec ()
return value of Stringcount pcre_exec ()
Stringname Capture String Name
Buffer used by buffer to store
BufferSize Buffer Size

Example:

Copy Code code as follows:

Line2730 int rc = pcre_copy_named_substring (Re, (char *) bptr, use_offsets,

Count, (char *) copynamesptr, Copybuffer, sizeof (Copybuffer));


5. Pcre_copy_substring

Prototype:
#include <pcre.h>
int pcre_copy_substring (const char *subject, int *ovector, int stringcount, int stringnumber, char *buffer, int buffersize );

Function: Gets the captured string based on the number.

Parameters:
Pattern of code Success matching
Subject matching string
Offset vector used by ovectorpcre_exec ()
return value of Stringcount pcre_exec ()
Stringnumber Capture String number
Buffer used by buffer to store
BufferSize Buffer Size

Example:

Copy Code code as follows:

Line2730 int rc = pcre_copy_substring ((char *) bptr, use_offsets, Count,

I, Copybuffer, sizeof (Copybuffer));


6. Pcre_dfa_exec

Prototype:
#include <pcre.h>
int pcre_dfa_exec (const pcre *code, const Pcre_extra *extra, const char *subject, int length, int startoffset, int options , int *ovector, int ovecsize, int *workspace, int wscount);

Function: Use a compiled pattern to match, using a non-traditional approach to the DFA, just one scan of the matching string (incompatible with Perl).

Parameters:
Code compiles a good pattern
Extra points to a PCRE_EXTRA structure, which can be null
Subject needs a matching string
Length matching string lengths (Byte)
Startoffset the starting position of the match
Options option Bit
Ovector an integer array that points to a result
Ovecsize array Size
Workspace a workspace array
Wscount array Size

Example:

Copy Code code as follows:

Line2730 count = pcre_dfa_exec (Re, Extra, (char *) bptr, Len, Start_offset,

Options | G_notempty, Use_offsets, use_size_offsets, workspace,

sizeof (workspace)/sizeof (int));


7. Pcre_copy_substring

Prototype:
#include <pcre.h>
int pcre_exec (const pcre *code, const Pcre_extra *extra, const char *subject, int length, int startoffset, int options, in T *ovector, int ovecsize);

Function: Use a compiled pattern to match, using a similar algorithm to Perl, to return the offset of the matching string.

Parameters:
Code compiles a good pattern
Extra points to a PCRE_EXTRA structure, which can be null
Subject needs a matching string
Length matching string lengths (Byte)
Startoffset the starting position of the match
Options option Bit
Ovector an integer array that points to a result
Ovecsize array Size

8. pcre_free_substring

Prototype:
#include <pcre.h>
void pcre_free_substring (const char *stringptr);

Function: Frees the memory space requested by pcre_get_substring () and pcre_get_named_substring ().

Parameters:
Stringptr Pointer to string

Example:

Copy Code code as follows:

Line2730 const char *substring;

int rc = pcre_get_substring ((char *) bptr, use_offsets, Count,

I, &substring);

......

pcre_free_substring (substring);


9. Pcre_free_substring_list

Prototype:
#include <pcre.h>
void pcre_free_substring_list (const char **stringptr);

Function: Frees the memory space requested by pcre_get_substring_list.

Parameters:
Stringptr pointer to an array of strings

Example:

Copy Code code as follows:

Line2773 const char **stringlist;
int rc = pcre_get_substring_list ((char *) bptr, use_offsets, Count,
......
Pcre_free_substring_list (stringlist);

Pcre_fullinfo

Prototype:
#include <pcre.h>
int Pcre_fullinfo (const pcre *code, const Pcre_extra *extra, int what, void *where);

Function: Returns the information of the compiled schema.

Parameters:
Code compiles a good pattern
Extra the return value of Pcre_study (), or null
What what information?
where storage location

Example:

Copy Code code as follows:

Line997 if (rc = Pcre_fullinfo (Re, study, option, PTR) < 0)
fprintf (outfile, "Error%d from Pcre_fullinfo (%d)/n", RC, option);
}

pcre_get_named_substring.

Prototype:
#include <pcre.h>
int pcre_get_named_substring (const pcre *code, const char *subject, int *ovector, int stringcount, const char *stringname, const char **stringptr);

Function: Gets the captured string based on the number.

Parameters:
Pattern of code Success matching
Subject matching string
Offset vector used by ovectorpcre_exec ()
return value of Stringcount pcre_exec ()
Stringname Capture String Name
Stringptr The string pointer that holds the result

Example:

Copy Code code as follows:

Line2759 const char *substring;
int rc = Pcre_get_named_substring (Re, (char *) bptr, use_offsets,
Count, (char *) getnamesptr, &substring);

Pcre_get_stringnumber

Prototype:
#include <pcre.h>
int Pcre_get_stringnumber (const pcre *code, const char *name);

function: Gets the corresponding number based on the name of the named capture.

Parameters:
Pattern of code Success matching
Name capture names

Pcre_get_substring

Prototype:
#include <pcre.h>
int pcre_get_substring (const char *subject, int *ovector, int stringcount, int stringnumber, const char **stringptr);

Function: Gets a matching substring.

Parameters:
Subject successfully matched string
Offset vector used by ovectorpcre_exec ()
return value of Stringcount pcre_exec ()
Stringnumber the string number obtained
STRINGPTR string pointer

Pcre_get_substring_list

Prototype:
#include <pcre.h>
int pcre_get_substring_list (const char *subject, int *ovector, int stringcount, const char ***listptr);

Function: Gets all substrings that match.

Parameters:
Subject successfully matched string
Offset vector used by ovectorpcre_exec ()
return value of Stringcount pcre_exec ()
Listptr A pointer to a list of strings

Pcre_info

Prototype:
#include <pcre.h>
int Pcre_info (const pcre *code, int *optptr, int *firstcharptr);

Obsolete, using pcre_fullinfo substitution.

Pcre_maketables

Prototype:
#include <pcre.h>
Const unsigned char *pcre_maketables (void);

Function: Generates a character table in which each element's value is not greater than 256 and can be passed to Pcre_compile () to replace the built-in character sheet.

Parameters:

Example:
Line2759 tables = Pcre_maketables ();

Pcre_refcount

Prototype:
#include <pcre.h>
int Pcre_refcount (pcre *code, int adjust);

Function: Reference count for compilation mode.

Parameters:
Code-compiled pattern

Adjust-adjusted reference count value

Pcre_study

Prototype:
#include <pcre.h>
Pcre_extra *pcre_study (const pcre *code, int options, const char **errptr);

Function: Learn from the compiled schema and extract information that can speed up the matching process.

Parameters:
Code-compiled pattern
Options option
ERRPTR error message

Example:
Line1797 extra = Pcre_study (Re, study_options, &error);

Pcre_version

Prototype:
#include <pcre.h>
Char *pcre_version (void);

Feature: Returns version information for Pcre.
Parameters:
Example:
Line1384 if (!quiet) fprintf (outfile, PCRE version%s/n/n, pcre_version ());

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.