regExp Class Reference

Wrapper around POSIX extended regular expressions. More...

Public Member Functions

 regExp ()
 Construct null. More...
 
 regExp (const char *, const bool ignoreCase=false)
 Construct from character array, optionally ignoring case. More...
 
 regExp (const std::string &, const bool ignoreCase=false)
 Construct from std::string (or string), optionally ignoring case. More...
 
 regExp (const regExp &)=delete
 Disallow default bitwise copy construction. More...
 
 ~regExp ()
 Destructor. More...
 
bool empty () const
 Return true if a precompiled expression does not exist. More...
 
bool exists () const
 Does a precompiled expression exist? More...
 
int ngroups () const
 Return the number of (groups) More...
 
void set (const char *, const bool ignoreCase=false) const
 Compile pattern into a regular expression,. More...
 
void set (const std::string &, const bool ignoreCase=false) const
 Compile pattern into a regular expression,. More...
 
bool clear () const
 Release precompiled expression. More...
 
std::string::size_type find (const std::string &str) const
 Find position within string. More...
 
bool match (const std::string &) const
 Return true if it matches the entire string. More...
 
bool match (const std::string &, List< std::string > &groups) const
 Return true if it matches and sets the sub-groups matched. More...
 
bool match (const std::string &, List< string > &groups) const
 Return true if it matches and sets the sub-groups matched. More...
 
bool search (const std::string &str) const
 Return true if the regex was found within string. More...
 
void operator= (const regExp &)=delete
 Disallow default bitwise assignment. More...
 
void operator= (const char *)
 Assign and compile pattern from a character array. More...
 
void operator= (const std::string &)
 Assign and compile pattern from string. More...
 

Static Public Member Functions

static bool meta (char c)
 Is character a regular expression meta-character? More...
 

Detailed Description

Wrapper around POSIX extended regular expressions.

The PCRE '(?i)' extension is provided to compile the regular expression as being case-insensitive.

See also
The manpage regex(7) for more information about POSIX regular expressions. These differ somewhat from Perl and sed regular expressions.
Source files

Definition at line 61 of file regExp.H.

Constructor & Destructor Documentation

◆ regExp() [1/4]

regExp ( )

Construct null.

Definition at line 84 of file regExp.C.

◆ regExp() [2/4]

regExp ( const char *  pattern,
const bool  ignoreCase = false 
)

Construct from character array, optionally ignoring case.

Definition at line 90 of file regExp.C.

◆ regExp() [3/4]

regExp ( const std::string &  pattern,
const bool  ignoreCase = false 
)

Construct from std::string (or string), optionally ignoring case.

Definition at line 98 of file regExp.C.

◆ regExp() [4/4]

regExp ( const regExp )
delete

Disallow default bitwise copy construction.

◆ ~regExp()

~regExp ( )

Destructor.

Definition at line 108 of file regExp.C.

References regExp::clear().

Here is the call graph for this function:

Member Function Documentation

◆ meta()

static bool meta ( char  c)
inlinestatic

Is character a regular expression meta-character?

any character: '.'
quantifiers: '*', '+', '?'
grouping: '(', '|', ')'
range: '[', ']'
Don't bother checking for '{digit}' bounds

Definition at line 92 of file regExp.H.

Referenced by wordRe::meta().

Here is the caller graph for this function:

◆ empty()

bool empty ( ) const
inline

Return true if a precompiled expression does not exist.

Definition at line 128 of file regExp.H.

◆ exists()

bool exists ( ) const
inline

Does a precompiled expression exist?

Definition at line 134 of file regExp.H.

Referenced by wordRe::compile(), wordRe::isPattern(), wordRe::match(), and wordRe::recompile().

Here is the caller graph for this function:

◆ ngroups()

int ngroups ( ) const
inline

Return the number of (groups)

Definition at line 140 of file regExp.H.

References regExp::clear(), regExp::find(), and regExp::match().

Here is the call graph for this function:

◆ set() [1/2]

void set ( const char *  pattern,
const bool  ignoreCase = false 
) const

Compile pattern into a regular expression,.

optionally ignoring case

Definition at line 116 of file regExp.C.

References regExp::clear(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, and Foam::nl.

Referenced by wordRe::compile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set() [2/2]

void set ( const std::string &  pattern,
const bool  ignoreCase = false 
) const

Compile pattern into a regular expression,.

optionally ignoring case

Definition at line 163 of file regExp.C.

◆ clear()

bool clear ( ) const

Release precompiled expression.

Returns true if precompiled expression existed before clear

Definition at line 169 of file regExp.C.

Referenced by wordRe::clear(), wordRe::compile(), regExp::ngroups(), wordRe::operator=(), regExp::set(), wordRe::uncompile(), and regExp::~regExp().

Here is the caller graph for this function:

◆ find()

std::string::size_type find ( const std::string &  str) const

Find position within string.

Returns the index where it begins or string::npos if not found

Definition at line 184 of file regExp.C.

Referenced by regExp::ngroups(), and regExp::search().

Here is the caller graph for this function:

◆ match() [1/3]

bool match ( const std::string &  str) const

Return true if it matches the entire string.

The begin-of-line (^) and end-of-line ($) anchors are implicit

Definition at line 201 of file regExp.C.

Referenced by keyType::match(), regExp::match(), wordRe::match(), regExp::ngroups(), and STARCDsurfaceFormatCore::readInpCellTable().

Here is the caller graph for this function:

◆ match() [2/3]

bool match ( const std::string &  str,
List< std::string > &  groups 
) const

Return true if it matches and sets the sub-groups matched.

The begin-of-line (^) and end-of-line ($) anchors are implicit

Definition at line 225 of file regExp.C.

References regExp::match().

Here is the call graph for this function:

◆ match() [3/3]

bool match ( const std::string &  str,
List< string > &  groups 
) const

Return true if it matches and sets the sub-groups matched.

The begin-of-line (^) and end-of-line ($) anchors are implicit

Definition at line 235 of file regExp.C.

◆ search()

bool search ( const std::string &  str) const
inline

Return true if the regex was found within string.

Definition at line 180 of file regExp.H.

References regExp::find(), and regExp::operator=().

Here is the call graph for this function:

◆ operator=() [1/3]

void operator= ( const regExp )
delete

Disallow default bitwise assignment.

Referenced by regExp::search().

Here is the caller graph for this function:

◆ operator=() [2/3]

void operator= ( const char *  pat)

Assign and compile pattern from a character array.

Always case sensitive

Definition at line 246 of file regExp.C.

◆ operator=() [3/3]

void operator= ( const std::string &  pat)

Assign and compile pattern from string.

Always case sensitive

Definition at line 252 of file regExp.C.


The documentation for this class was generated from the following files: