Apache2
ap_regex.h File Reference

Apache Regex defines. More...

#include "apr.h"
Include dependency graph for ap_regex.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ap_regex_t
 
struct  ap_regmatch_t
 
struct  ap_rxplus_t
 

Macros

#define AP_REG_ICASE   0x01
 
#define AP_REG_NEWLINE   0x02
 
#define AP_REG_NOTBOL   0x04
 
#define AP_REG_NOTEOL   0x08
 
#define AP_REG_EXTENDED   (0)
 
#define AP_REG_NOSUB   (0)
 
#define AP_REG_MULTI   0x10
 
#define AP_REG_NOMEM   0x20
 
#define AP_REG_DOTALL   0x40
 
#define AP_REG_NOTEMPTY   0x080
 
#define AP_REG_ANCHORED   0x100
 
#define AP_REG_DOLLAR_ENDONLY   0x200
 
#define AP_REG_NO_DEFAULT   0x400
 
#define AP_REG_MATCH   "MATCH_"
 
#define AP_REG_DEFAULT   (AP_REG_DOTALL|AP_REG_DOLLAR_ENDONLY)
 

Enumerations

enum  { AP_REG_PCRE_COMPILED = 0 , AP_REG_PCRE_LOADED }
 
enum  { AP_REG_ASSERT = 1 , AP_REG_ESPACE , AP_REG_INVARG , AP_REG_NOMATCH }
 

Functions

const char * ap_pcre_version_string (int which)
 
int ap_regcomp_get_default_cflags (void)
 
void ap_regcomp_set_default_cflags (int cflags)
 
int ap_regcomp_default_cflag_by_name (const char *name)
 
int ap_regcomp (ap_regex_t *preg, const char *regex, int cflags)
 
int ap_regexec (const ap_regex_t *preg, const char *string, apr_size_t nmatch, ap_regmatch_t *pmatch, int eflags)
 
int ap_regexec_len (const ap_regex_t *preg, const char *buff, apr_size_t len, apr_size_t nmatch, ap_regmatch_t *pmatch, int eflags)
 
apr_size_t ap_regerror (int errcode, const ap_regex_t *preg, char *errbuf, apr_size_t errbuf_size)
 
int ap_regname (const ap_regex_t *preg, apr_array_header_t *names, const char *prefix, int upper)
 
void ap_regfree (ap_regex_t *preg)
 
ap_rxplus_tap_rxplus_compile (apr_pool_t *pool, const char *pattern)
 
int ap_rxplus_exec (apr_pool_t *pool, ap_rxplus_t *rx, const char *pattern, char **newpattern)
 
int ap_rxplus_nmatch (ap_rxplus_t *rx)
 
void ap_rxplus_match (ap_rxplus_t *rx, int n, int *len, const char **match)
 
char * ap_rxplus_pmatch (apr_pool_t *pool, ap_rxplus_t *rx, int n)
 

Detailed Description

Apache Regex defines.

Macro Definition Documentation

◆ AP_REG_ANCHORED

#define AP_REG_ANCHORED   0x100

Match at the first position

◆ AP_REG_DEFAULT

#define AP_REG_DEFAULT   (AP_REG_DOTALL|AP_REG_DOLLAR_ENDONLY)

◆ AP_REG_DOLLAR_ENDONLY

#define AP_REG_DOLLAR_ENDONLY   0x200

'$' matches at end of subject string only

◆ AP_REG_DOTALL

#define AP_REG_DOTALL   0x40

perl's /s flag

◆ AP_REG_EXTENDED

#define AP_REG_EXTENDED   (0)

unused

◆ AP_REG_ICASE

#define AP_REG_ICASE   0x01

use a case-insensitive match

◆ AP_REG_MATCH

#define AP_REG_MATCH   "MATCH_"

suggested prefix for ap_regname

◆ AP_REG_MULTI

#define AP_REG_MULTI   0x10

perl's /g (needs fixing)

◆ AP_REG_NEWLINE

#define AP_REG_NEWLINE   0x02

don't match newlines against '.' etc

◆ AP_REG_NO_DEFAULT

#define AP_REG_NO_DEFAULT   0x400

Don't implicitely add AP_REG_DEFAULT options

◆ AP_REG_NOMEM

#define AP_REG_NOMEM   0x20

nomem in our code

◆ AP_REG_NOSUB

#define AP_REG_NOSUB   (0)

unused

◆ AP_REG_NOTBOL

#define AP_REG_NOTBOL   0x04

^ will not match against start-of-string

◆ AP_REG_NOTEMPTY

#define AP_REG_NOTEMPTY   0x080

Empty match not valid

◆ AP_REG_NOTEOL

#define AP_REG_NOTEOL   0x08

$ will not match against end-of-string

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
AP_REG_PCRE_COMPILED 
AP_REG_PCRE_LOADED 

PCRE version used during program compilation PCRE version loaded at runtime

◆ anonymous enum

anonymous enum
Enumerator
AP_REG_ASSERT 
AP_REG_ESPACE 

internal error ?

AP_REG_INVARG 

failed to get memory

AP_REG_NOMATCH 

invalid argument match failed

Function Documentation

◆ ap_pcre_version_string()

const char* ap_pcre_version_string ( int  which)

Return PCRE version string.

Parameters
whichEither AP_REG_PCRE_COMPILED (PCRE version used during program compilation) or AP_REG_PCRE_LOADED (PCRE version used at runtime)
Returns
The PCRE version string

◆ ap_regcomp()

int ap_regcomp ( ap_regex_t preg,
const char *  regex,
int  cflags 
)

Compile a regular expression.

Parameters
pregReturned compiled regex
regexThe regular expression string
cflagsBitwise OR of AP_REG_* flags (ICASE and NEWLINE supported, other flags are ignored)
Returns
Zero on success or non-zero on error

◆ ap_regcomp_default_cflag_by_name()

int ap_regcomp_default_cflag_by_name ( const char *  name)

Get the AP_REG_* corresponding to the string.

Parameters
nameThe name (i.e. AP_REG_<name>)
Returns
The AP_REG_*, or zero if the string is unknown

◆ ap_regcomp_get_default_cflags()

int ap_regcomp_get_default_cflags ( void  )

Get default compile flags

Returns
Bitwise OR of AP_REG_* flags

◆ ap_regcomp_set_default_cflags()

void ap_regcomp_set_default_cflags ( int  cflags)

Set default compile flags

Parameters
cflagsBitwise OR of AP_REG_* flags

◆ ap_regerror()

apr_size_t ap_regerror ( int  errcode,
const ap_regex_t preg,
char *  errbuf,
apr_size_t  errbuf_size 
)

Return the error code returned by regcomp or regexec into error messages

Parameters
errcodethe error code returned by regexec or regcomp
pregThe precompiled regex
errbufA buffer to store the error in
errbuf_sizeThe size of the buffer

◆ ap_regexec()

int ap_regexec ( const ap_regex_t preg,
const char *  string,
apr_size_t  nmatch,
ap_regmatch_t pmatch,
int  eflags 
)

Match a NUL-terminated string against a pre-compiled regex.

Parameters
pregThe pre-compiled regex
stringThe string to match
nmatchProvide information regarding the location of any matches
pmatchProvide information regarding the location of any matches
eflagsBitwise OR of AP_REG_* flags (NOTBOL and NOTEOL supported, other flags are ignored)
Returns
0 for successful match, AP_REG_NOMATCH otherwise

◆ ap_regexec_len()

int ap_regexec_len ( const ap_regex_t preg,
const char *  buff,
apr_size_t  len,
apr_size_t  nmatch,
ap_regmatch_t pmatch,
int  eflags 
)

Match a string with given length against a pre-compiled regex. The string does not need to be NUL-terminated.

Parameters
pregThe pre-compiled regex
buffThe string to match
lenLength of the string to match
nmatchProvide information regarding the location of any matches
pmatchProvide information regarding the location of any matches
eflagsBitwise OR of AP_REG_* flags (NOTBOL and NOTEOL supported, other flags are ignored)
Returns
0 for successful match, AP_REG_NOMATCH otherwise

◆ ap_regfree()

void ap_regfree ( ap_regex_t preg)

Destroy a pre-compiled regex.

Parameters
pregThe pre-compiled regex to free.

◆ ap_regname()

int ap_regname ( const ap_regex_t preg,
apr_array_header_t names,
const char *  prefix,
int  upper 
)

Return an array of named regex backreferences

Parameters
pregThe precompiled regex
namesThe array to which the names will be added
prefixAn optional prefix to add to the returned names. AP_REG_MATCH is the recommended prefix.
upperIf non zero, uppercase the names

◆ ap_rxplus_compile()

ap_rxplus_t* ap_rxplus_compile ( apr_pool_t pool,
const char *  pattern 
)

Compile a pattern into a regexp. supports perl-like formats match-string /match-string/flags s/match-string/replacement-string/flags Intended to support more perl-like stuff as and when round tuits happen match-string is anything supported by ap_regcomp replacement-string is a substitution string as supported in ap_pregsub flags should correspond with perl syntax: treat failure to do so as a bug (documentation TBD)

Parameters
poolPool to allocate from
patternPattern to compile
Returns
Compiled regexp, or NULL in case of compile/syntax error

◆ ap_rxplus_exec()

int ap_rxplus_exec ( apr_pool_t pool,
ap_rxplus_t rx,
const char *  pattern,
char **  newpattern 
)

Apply a regexp operation to a string.

Parameters
poolPool to allocate from
rxThe regex match to apply
patternThe string to apply it to NOTE: This MUST be kept in scope to use regexp memory
newpatternThe modified string (ignored if the operation doesn't modify the string)
Returns
Number of times a match happens. Normally 0 (no match) or 1 (match found), but may be greater if a transforming pattern is applied with the 'g' flag.

◆ ap_rxplus_match()

void ap_rxplus_match ( ap_rxplus_t rx,
int  n,
int len,
const char **  match 
)

Get a pointer to a match from regex memory NOTE: this relies on the match pattern from the last call to ap_rxplus_exec still being valid (i.e. not freed or out-of-scope)

Parameters
rxThe regexp
nThe match number to retrieve (must be between 0 and nmatch)
lenReturns the length of the match.
matchReturns the match pattern

◆ ap_rxplus_nmatch()

int ap_rxplus_nmatch ( ap_rxplus_t rx)

Number of matches in the regexp operation's memory This may be 0 if no match is in memory, or up to nmatch from compilation

Parameters
rxThe regexp
Returns
Number of matches in memory

◆ ap_rxplus_pmatch()

char* ap_rxplus_pmatch ( apr_pool_t pool,
ap_rxplus_t rx,
int  n 
)

Get a match from regex memory in a string copy NOTE: this relies on the match pattern from the last call to ap_rxplus_exec still being valid (i.e. not freed or out-of-scope)

Parameters
poolPool to allocate from
rxThe regexp
nThe match number to retrieve (must be between 0 and nmatch)
Returns
The matched string