Reguläre Ausdrücke

Minimalbeispiel

#include <regex>

std::string        s = "Hello, World";
std::regex         r = "[aeiou]";
std::match_results m;

if (std::regex_match (s, r)) {
	std::cout << s << " contains vocals.\n";
}
if (std::regex_search (s, m, r)) {
	std::cout << std::regex_replace (s, r, "Regex") << "\n";
}

Konstruktion

regex

std::regex typedef std::basic_regex<char>
public:
typedef flag_type;
typedef locale_type;
static const flag_type icase;
static const flag_type nosubs;
static const flag_type optimize;
static const flag_type collate;
static const flag_type ECMAScript;
static const flag_type basic;
static const flag_type extended;
static const flag_type awk;
static const flag_type grep;
static const flag_type egrep;
Konstruktion
regex ();
explicit regex (const char * ptr, flag_type flags = ECMAScript);
regex (const char * ptr, size_type len, flag_type flags = ECMAScript);
explicit regex (const string & str, flag_type flags = ECMAScript);
explicit regex (InputIterator first,
 InputIterator last,flag_type flags = ECMAScript);
regex (const regex & right);
Modifikation
regex & operator= (const regex & right);
regex & operator= (const string & str);
regex & operator= (const char * ptr);
regex & assign (const regex & right);
regex & assign (const string & str, flag_type flags = ECMAScript);
regex & assign (const char * ptr, flag_type flags = ECMAScript);
regex & assign (const char * ptr, size_type len, flag_type flags = ECMAScript);
regex & assign (InputIterator first,
 InputIterator last,flag_type flags = ECMAScript);
void swap (regex & other) throw ();
Observation
locale_type imbue (locale_type loc);
locale_type getloc () const;
unsigned mark_count () const;
flag_type flags () const;

Ergebnisse

match_results

std::match_results
public:
typedef sub_matchvalue_type;
Konstruktion
explicit match_results ();
match_results (const match_results & right);
Modifikation
match_results & operator= (const match_results & right);
void swap (const match_results & other) throw ();
Iteration
const_reference prefix () const;
const_reference suffix () const;
const_iterator begin () const;
const_iterator end () const;
Observation
string_type format (const string_type & fmt, match_flag_type flags = format_default) const;
OutputIteratorformat(OutputIterator out,
const string_type & fmt, match_flag_type flags = format_default) const;
difference_type position (size_type sub = 0) const;
difference_type length (size_type sub = 0) const;
string_type str (size_type sub = 0) const;
const_reference operator[] (size_type n) const;
Kapazität
bool empty () const;
size_type size () const;
size_type max_size () const;
allocator_type get_allocator () const;

sub_match

std::sub_match : std::pair<BidirectionalIterator, BidirectionalIterator>
public:
bool matched;
int compareg (const sub_match & right) const;g
int compareg (const string & right) const;g
int compareg (const value_type * right) const;g
difference_type lengthg () const;g
string strg () const;g
operator string () const;g
class regex_error;
namespace regex_constants {
	static const error_type error_badbrace, error_badrepeat, error_brace, error_brack, error_collate, error_complexity, error_ctype, error_escape, error_paren, error_range, error_space, error_stack, error_backref;
}

Methoden

Konstanten
static const match_flag_typematch_default
match_any
match_not_bol
match_not_eol
match_not_bow
match_not_eow
match_not_null
match_partial
match_prev_avail
match_continuous
Prüfung
bool regex_match (const char * ptr, match_results & match, const regex & re, flags = match_default);
bool regex_match (const char * ptr, const regex & re, flags = match_default);
bool regex_match (const string & str, match_results & match, const regex & re, flags = match_default);
bool regex_match (const string & str, const regex & re, flags = match_default);
bool regex_match (BidirectionalIterator first,
BidirectionalIterator last, match_results & match, const regex & re, flags = match_default);
bool regex_match (BidirectionalIterator first,
BidirectionalIterator last, const regex & re, flags = match_default);
bool regex_search (const char * ptr, match_results & match, const regex & re, flags = match_default);
bool regex_search (const char * ptr, const regex & re, flags = match_default);
bool regex_search (const string & str, match_results & match, const regex & re, flags = match_default);
bool regex_search (const string & str, const regex & re, flags = match_default);
bool regex_search (BidirectionalIterator first,
BidirectionalIterator last, match_results & match, const regex & re, flags = match_default);
bool regex_search (BidirectionalIterator first,
BidirectionalIterator last, const regex & re, flags = match_default);
Ersetzung
string regex_replace (const string & str, const regex & re, const string & fmt, flags = match_default);
OutputIterator regex_replace (OutputIterator out,
BidirectionalIterator first,
BidirectionalIterator last, const regex & re, const string & fmt, flags = match_default);