wex v24.04.0
Classes | Public Types | Public Member Functions | List of all members
wex::regex Class Reference

This class offers regular expression matching. More...

#include <wex/core/regex.h>

Classes

class  data
 This class contains the regex data. More...
 

Public Types

typedef std::vector< std::string > match_t
 Type that specifies the matches.
 
typedef std::function< void(const match_t &) function_t)
 Callback type.
 
typedef std::vector< std::string > regex_v_t
 Type that specifies a vector with regular expressions.
 
typedef std::pair< std::string, function_tregex_c_t
 Type that specifies pair of regular expression and callback.
 
typedef std::vector< regex_c_tregex_v_c_t
 Type that specifies a vector with regular expressions and callbacks.
 

Public Member Functions

 regex (const data &)
 Constructor, provide regular expression data.
 
 regex (const std::string &regex, std::regex::flag_type flags=std::regex::ECMAScript)
 Constructor, provide regular expression string and regex flags.
 
 regex (const std::string &regex, function_t f, std::regex::flag_type flags=std::regex::ECMAScript)
 Constructor, provide regular expression string, callback and regex flags.
 
 regex (const regex_v_t &regex, std::regex::flag_type flags=std::regex::ECMAScript)
 Constructor, provide vector with regular expressions and regex flags.
 
 regex (const regex_v_c_t &regex, std::regex::flag_type flags=std::regex::ECMAScript)
 Constructor, provide vector with regular expressions, callbacks and regex flags.
 
const std::string operator[] (size_t pos) const
 Returns requested submatch element.
 
const std::string back () const
 Returns the last (sub)match.
 
bool empty () const
 Returns true if matches is empty.
 
int match (const std::string &text)
 Regular expression match.
 
const data match_data () const
 Returns the data element that matched.
 
int match_no () const
 Returns the data regex index that matched, or -1 if no match was found.
 
bool replace (std::string &text, const std::string &replacement, std::regex_constants::match_flag_type=std::regex_constants::format_sed) const
 After match or search, replace text with replacement.
 
int search (const std::string &text)
 Regular expression search.
 
size_t size () const
 Returns number of submatches.
 

Detailed Description

This class offers regular expression matching.

Member Function Documentation

◆ back()

const std::string wex::regex::back ( ) const

Returns the last (sub)match.

Returns empty string if no matches present.

◆ match()

int wex::regex::match ( const std::string & text)

Regular expression match.

Returns:

  • -1: if text does not match or there is an error
  • 0: if text matches, but no submatches present.
  • >0: it fills submatches, and returns number of submatches.

◆ operator[]()

const std::string wex::regex::operator[] ( size_t pos) const

Returns requested submatch element.

Returns empty string if pos beyond index.

◆ replace()

bool wex::regex::replace ( std::string & text,
const std::string & replacement,
std::regex_constants::match_flag_type = std::regex_constants::format_sed ) const

After match or search, replace text with replacement.

Returns true if the regex iterator is available, because of successful match or search.

◆ search()

int wex::regex::search ( const std::string & text)

Regular expression search.

Returns:

  • -1: if text does not match or there is an error
  • 0: if text matches, but no submatches present.
  • >0: it fills submatches, and returns number of submatches.