PIP 5.5.3
Platform-Independent Primitives
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
PIRegularExpression Class Reference

Regular expression class Class for working with regular expressions. More...

#include <piregularexpression.h>

Classes

class  Matcher
 Class containing regular expression match results. More...
 

Public Types

enum  Option {
  None = 0x0 , CaseInsensitive = 0x01 , Singleline = 0x02 , Multiline = 0x04 ,
  InvertedGreediness = 0x08 , Extended = 0x10
}
 Options for regular expression matching behavior. More...
 
typedef PIFlags< OptionOptions
 Combination of regular expression options.
 

Public Member Functions

 PIRegularExpression (const PIString &pattern={}, Options opt=None)
 Creates regular expression with given pattern and options. More...
 
 PIRegularExpression (const PIRegularExpression &o)
 Creates copy of regular expression. More...
 
PIRegularExpressionoperator= (const PIRegularExpression &o)
 Assigns regular expression. More...
 
 ~PIRegularExpression ()
 Destroys regular expression object.
 
PIString pattern () const
 Returns regular expression pattern.
 
Options options () const
 Returns regular expression options.
 
void setPattern (const PIString &pattern)
 Sets regular expression pattern. More...
 
void setPattern (const PIString &pattern, Options opt)
 Sets regular expression pattern and options. More...
 
bool isValid () const
 Returns true if regular expression is valid.
 
bool isNotValid () const
 Returns true if regular expression is not valid.
 
PIString errorString () const
 Returns error description if pattern is invalid.
 
int errorPosition () const
 Returns position of error in pattern.
 
int captureGroupsCount () const
 Gets the number of capture groups in the pattern.
 
PIStringList captureGroupNames () const
 Gets the list of named capture groups.
 
PIString captureGroupName (int index) const
 Gets the name of capture group by index. More...
 
int captureGroupIndex (const PIString &gname) const
 Gets the index of named capture group. More...
 
Matcher match (const PIString &subject, size_t offset=0) const
 Matches regular expression against deep copy of subject string. More...
 
Matcher match (PIString &subject, size_t offset=0) const
 Matches regular expression against subject string. More...
 
Matcher match (PIString &&subject, size_t offset=0) const
 Matches regular expression against subject string. More...
 
Matcher matchIterator (const PIString &subject, size_t offset=0) const
 Prepere match regular expression against deep copy of subject string. More...
 
Matcher matchIterator (PIString &subject, size_t offset=0) const
 Prepere match regular expression against subject string. More...
 
Matcher matchIterator (PIString &&subject, size_t offset=0) const
 Prepere match regular expression against subject string. More...
 

Static Public Member Functions

static PIRegularExpression fromGlob (const PIString &pattern, Options opt=None)
 Creates regular expression from glob pattern. More...
 
static PIRegularExpression fromPOSIX (const PIString &pattern, Options opt=None)
 Creates regular expression from POSIX pattern. More...
 

Detailed Description

Regular expression class Class for working with regular expressions.

Member Enumeration Documentation

◆ Option

Options for regular expression matching behavior.

Enumerator
None 

No special options

CaseInsensitive 

Case insensitive matching

Singleline 

Dot matches newline

Multiline 

^ and $ match at line boundaries

InvertedGreediness 

Quantifiers are non-greedy by default

Extended 

Extended pattern syntax

Constructor & Destructor Documentation

◆ PIRegularExpression() [1/2]

PIRegularExpression::PIRegularExpression ( const PIString pattern = {},
Options  opt = None 
)

Creates regular expression with given pattern and options.

Parameters
patternRegular expression pattern
optMatching options

◆ PIRegularExpression() [2/2]

PIRegularExpression::PIRegularExpression ( const PIRegularExpression o)

Creates copy of regular expression.

Parameters
oSource regular expression

Member Function Documentation

◆ operator=()

PIRegularExpression & PIRegularExpression::operator= ( const PIRegularExpression o)

Assigns regular expression.

Parameters
oSource regular expression

◆ setPattern() [1/2]

void PIRegularExpression::setPattern ( const PIString pattern)

Sets regular expression pattern.

Parameters
patternNew pattern

◆ setPattern() [2/2]

void PIRegularExpression::setPattern ( const PIString pattern,
Options  opt 
)

Sets regular expression pattern and options.

Parameters
patternNew pattern
optNew options

◆ captureGroupName()

PIString PIRegularExpression::captureGroupName ( int  index) const

Gets the name of capture group by index.

Parameters
indexGroup index

◆ captureGroupIndex()

int PIRegularExpression::captureGroupIndex ( const PIString gname) const

Gets the index of named capture group.

Parameters
gnameGroup name

◆ match() [1/3]

PIRegularExpression::Matcher PIRegularExpression::match ( const PIString subject,
size_t  offset = 0 
) const

Matches regular expression against deep copy of subject string.

Parameters
subjectString to match against
offsetStarting position for matching

◆ match() [2/3]

PIRegularExpression::Matcher PIRegularExpression::match ( PIString subject,
size_t  offset = 0 
) const

Matches regular expression against subject string.

Parameters
subjectString to match against
offsetStarting position for matching

◆ match() [3/3]

PIRegularExpression::Matcher PIRegularExpression::match ( PIString &&  subject,
size_t  offset = 0 
) const

Matches regular expression against subject string.

Parameters
subjectString to match against
offsetStarting position for matching

◆ matchIterator() [1/3]

PIRegularExpression::Matcher PIRegularExpression::matchIterator ( const PIString subject,
size_t  offset = 0 
) const

Prepere match regular expression against deep copy of subject string.

Parameters
subjectString to match against
offsetStarting position for matching

◆ matchIterator() [2/3]

PIRegularExpression::Matcher PIRegularExpression::matchIterator ( PIString subject,
size_t  offset = 0 
) const

Prepere match regular expression against subject string.

Parameters
subjectString to match against
offsetStarting position for matching

◆ matchIterator() [3/3]

PIRegularExpression::Matcher PIRegularExpression::matchIterator ( PIString &&  subject,
size_t  offset = 0 
) const

Prepere match regular expression against subject string.

Parameters
subjectString to match against
offsetStarting position for matching

◆ fromGlob()

PIRegularExpression PIRegularExpression::fromGlob ( const PIString pattern,
Options  opt = None 
)
static

Creates regular expression from glob pattern.

Parameters
patternGlob pattern
optMatching options

◆ fromPOSIX()

PIRegularExpression PIRegularExpression::fromPOSIX ( const PIString pattern,
Options  opt = None 
)
static

Creates regular expression from POSIX pattern.

Parameters
patternPOSIX pattern
optMatching options