libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
RegEx Class Reference

Regular expression wrapper around std::regex. More...

#include <regex.h>

Public Types

using Flag = std::regex_constants::syntax_option_type
 Syntax option flags for controlling regex behavior.
 

Public Member Functions

 RegEx (const String &pattern, Flag flags=DefaultFlags)
 Constructs a RegEx from a String pattern.
 
 RegEx (const char *pattern, Flag flags=DefaultFlags)
 Constructs a RegEx from a C string pattern.
 
RegExoperator= (const String &pattern)
 Assigns a new pattern to this regex.
 
String pattern () const
 Returns the current pattern string.
 
bool match (const String &str) const
 Tests whether the entire string matches the pattern.
 
bool search (const String &str) const
 Searches for the first occurrence of the pattern within the string.
 
StringList matches (const String &str) const
 Returns all non-overlapping matches of the pattern in the string.
 

Static Public Attributes

static constexpr Flag IgnoreCase = std::regex::icase
 Case-insensitive matching.
 
static constexpr Flag NoSubs = std::regex::nosubs
 Treat all sub-expressions as non-marking; no matches are stored.
 
static constexpr Flag Optimize = std::regex::optimize
 Optimize the regex for faster matching at the cost of slower construction.
 
static constexpr Flag Collate = std::regex::collate
 Make character ranges like "[a-b]" locale sensitive.
 
static constexpr Flag ECMAScript = std::regex::ECMAScript
 Use the Modified ECMAScript regular expression grammar.
 
static constexpr Flag Basic = std::regex::basic
 Use the basic POSIX regular expression grammar.
 
static constexpr Flag Extended = std::regex::extended
 Use the extended POSIX regular expression grammar.
 
static constexpr Flag Awk = std::regex::awk
 Use the awk POSIX regular expression grammar.
 
static constexpr Flag Grep = std::regex::grep
 Use the grep POSIX regular expression grammar.
 
static constexpr Flag EGrep = std::regex::egrep
 Use the egrep (grep -E) POSIX regular expression grammar.
 
static constexpr Flag DefaultFlags = ECMAScript | Optimize
 Default flags: ECMAScript grammar with optimization enabled.
 

Detailed Description

Regular expression wrapper around std::regex.

Provides a simplified interface for pattern matching, searching, and

Example
RegEx re("(\\d+)x(\\d+)");
auto match = re.match("1920x1080");
if(match.hasMatch()) {
String w = match.captured(1); // "1920"
String h = match.captured(2); // "1080"
}
Dynamic array container wrapping std::vector.
Definition list.h:40
Regular expression wrapper around std::regex.
Definition regex.h:34
bool match(const String &str) const
Tests whether the entire string matches the pattern.
Definition regex.h:110
Encoding-aware string class with copy-on-write semantics.
Definition string.h:35
extracting matches from strings using standard C++ regular expressions.

Constructor & Destructor Documentation

◆ RegEx() [1/2]

RegEx::RegEx ( const String pattern,
Flag  flags = DefaultFlags 
)
inline

Constructs a RegEx from a String pattern.

Parameters
patternThe regular expression pattern.
flagsSyntax option flags (default: DefaultFlags).

◆ RegEx() [2/2]

RegEx::RegEx ( const char pattern,
Flag  flags = DefaultFlags 
)
inline

Constructs a RegEx from a C string pattern.

Parameters
patternThe regular expression pattern.
flagsSyntax option flags (default: DefaultFlags).

Member Function Documentation

◆ match()

bool RegEx::match ( const String str) const
inline

Tests whether the entire string matches the pattern.

Parameters
strThe string to test.
Returns
True if the full string matches the regular expression.

◆ matches()

StringList RegEx::matches ( const String str) const
inline

Returns all non-overlapping matches of the pattern in the string.

Parameters
strThe string to search in.
Returns
A StringList containing every matching substring.

◆ operator=()

RegEx & RegEx::operator= ( const String pattern)
inline

Assigns a new pattern to this regex.

Parameters
patternThe new regular expression pattern.
Returns
Reference to this RegEx.

◆ pattern()

String RegEx::pattern ( ) const
inline

Returns the current pattern string.

Returns
The regular expression pattern.

◆ search()

bool RegEx::search ( const String str) const
inline

Searches for the first occurrence of the pattern within the string.

Parameters
strThe string to search in.
Returns
True if any substring matches the regular expression.

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