Base Framework
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
RegExp Class Reference

Regular expression. More...

#include <base/string/RegExp.h>

Inherits Object.

Classes

class  RegExpException
 Regular expression exception. More...
 
class  Substring
 Substring descriptor. More...
 

Public Member Functions

 RegExp () noexcept
 
 RegExp (const String &pattern, bool caseSensitivity=true)
 
bool isCaseSensitive () const noexcept
 
bool isValid () const noexcept
 
const StringgetPattern () const noexcept
 
void setCaseSensitivity (bool _caseSensitive) noexcept
 
void setPattern (const String &pattern)
 
bool doesMatch (const String &value, MemorySize start=0) const
 
Substring match (const String &value, MemorySize start=0) const
 
Substring match (const String &value, Array< Substring > &arguments, MemorySize start=0) const
 
 ~RegExp () noexcept
 

Static Public Member Functions

static bool isRegularExpression (const String &pattern, bool caseSensitive=true) noexcept
 

Protected Member Functions

void compile ()
 
void release () noexcept
 

Detailed Description

Regular expression.

Regular expression pattern matching.

Version
1.0

Constructor & Destructor Documentation

◆ RegExp() [1/2]

RegExp::RegExp ( )
noexcept

Initializes the regular expression in case sensitive mode.

◆ RegExp() [2/2]

RegExp::RegExp ( const String pattern,
bool  caseSensitivity = true 
)

Initializes the regular expression with the specified pattern.

Parameters
patternThe pattern.
caseSensitiveSpecifies the case sensitivity. Default is true.

◆ ~RegExp()

RegExp::~RegExp ( )
inlinenoexcept

Destroys the regular expression.

Member Function Documentation

◆ compile()

void RegExp::compile ( )
protected

Compiles the regular expression.

◆ doesMatch()

bool RegExp::doesMatch ( const String value,
MemorySize  start = 0 
) const

Returns true if the value matches the pattern.

◆ getPattern()

const String& RegExp::getPattern ( ) const
inlinenoexcept

Returns the pattern.

◆ isCaseSensitive()

bool RegExp::isCaseSensitive ( ) const
inlinenoexcept

Returns true if case sensitive.

◆ isRegularExpression()

static bool RegExp::isRegularExpression ( const String pattern,
bool  caseSensitive = true 
)
staticnoexcept

Returns true if the given expression is a valid regular expression.

◆ isValid()

bool RegExp::isValid ( ) const
inlinenoexcept

Returns true if the regular expression is valid.

◆ match() [1/2]

Substring RegExp::match ( const String value,
Array< Substring > &  arguments,
MemorySize  start = 0 
) const

Matches the specified string with the regular expression. Raises OutOfRange if the start index exceeds the end of the string to be matched.

Parameters
valueThe string to be matched.
argumentsThe array to receive the captured substrings from the matched string.
startThe start index. The default is 0.
Returns
The substring matched by the entire pattern.

◆ match() [2/2]

Substring RegExp::match ( const String value,
MemorySize  start = 0 
) const

Matches the specified string with the regular expression. Raises OutOfRange if the start index exceeds the end of the string to be matched.

Parameters
valueThe string to be matched.
startThe start index. The default is 0.
Returns
The substring matched by the entire pattern.

◆ release()

void RegExp::release ( )
protectednoexcept

Releases any resources.

◆ setCaseSensitivity()

void RegExp::setCaseSensitivity ( bool  _caseSensitive)
inlinenoexcept

Sets the case sensitivity mode.

Parameters
caseSensitiveSpecifies the case sensitivity. True selects case sensitive matching.

◆ setPattern()

void RegExp::setPattern ( const String pattern)

Sets the pattern of the regular expression.