Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Regular Expressions.

#include <boost/tr1/regex.hpp>

or

#include <regex>

This library provides comprehensive support for regular expressions, including either iterator or string based matching, searching, search-and-replace, iteration, and tokenization. Both POSIX and ECMAScript (JavaScript) regular expressions are supported. For more information see the Boost.Regex documentation.

namespace std {
namespace tr1 {

// [7.5] Regex constants
namespace regex_constants {

typedef bitmask_type syntax_option_type;
typedef bitmask_type match_flag_type;
typedef implementation-defined error_type;

} // namespace regex_constants

// [7.6] Class regex_error
class regex_error;

// [7.7] Class template regex_traits
template <class charT> struct regex_traits;

// [7.8] Class template basic_regex
template <class charT, class traits = regex_traits<charT> >
class basic_regex;

typedef basic_regex<char> regex;
typedef basic_regex<wchar_t> wregex;

// [7.8.6] basic_regex swap
template <class charT, class traits>
void swap(basic_regex<charT, traits>& e1,
         basic_regex<charT, traits>& e2);

// [7.9] Class template sub_match
template <class BidirectionalIterator>
class sub_match;

typedef sub_match<const char*> csub_match;
typedef sub_match<const wchar_t*> wcsub_match;
typedef sub_match<string::const_iterator> ssub_match;
typedef sub_match<wstring::const_iterator> wssub_match;

// [7.9.2] sub_match non-member operators

/* Comparison operators omitted for clarity.... */

template <class charT, class ST, class BiIter>
basic_ostream<charT, ST>&
   operator<<(basic_ostream<charT, ST>& os,
            const sub_match<BiIter>& m);

// [7.10] Class template match_results
template <class BidirectionalIterator,
         class Allocator = allocator<sub_match<BidirectionalIterator> > >
class match_results;

typedef match_results<const char*> cmatch;
typedef match_results<const wchar_t*> wcmatch;
typedef match_results<string::const_iterator> smatch;
typedef match_results<wstring::const_iterator> wsmatch;

// match_results comparisons
template <class BidirectionalIterator, class Allocator>
bool operator== (const match_results<BidirectionalIterator, Allocator>& m1,
               const match_results<BidirectionalIterator, Allocator>& m2);
template <class BidirectionalIterator, class Allocator>
bool operator!= (const match_results<BidirectionalIterator, Allocator>& m1,
               const match_results<BidirectionalIterator, Allocator>& m2);

// [7.10.6] match_results swap
template <class BidirectionalIterator, class Allocator>
void swap(match_results<BidirectionalIterator, Allocator>& m1,
         match_results<BidirectionalIterator, Allocator>& m2);

// [7.11.2] Function template regex_match
template <class BidirectionalIterator, class Allocator, class charT, class traits>
bool regex_match(BidirectionalIterator first,
               BidirectionalIterator last,
               match_results<BidirectionalIterator, Allocator>& m,
               const basic_regex<charT, traits>& e,
               regex_constants::match_flag_type flags = regex_constants::match_default);

template <class BidirectionalIterator, class charT, class traits>
bool regex_match(BidirectionalIterator first,
               BidirectionalIterator last,
               const basic_regex<charT, traits>& e,
               regex_constants::match_flag_type flags = regex_constants::match_default);

template <class charT, class Allocator, class traits>
bool regex_match(const charT* str,
               match_results<const charT*, Allocator>& m,
               const basic_regex<charT, traits>& e,
               regex_constants::match_flag_type flags = regex_constants::match_default);

template <class ST, class SA, class Allocator, class charT, class traits>
bool regex_match(const basic_string<charT, ST, SA>& s,
               match_results<typename basic_string<charT, ST, SA>::const_iterator,Allocator>& m,
               const basic_regex<charT, traits>& e,
               regex_constants::match_flag_type flags = regex_constants::match_default);

template <class charT, class traits>
bool regex_match(const charT* str,
               const basic_regex<charT, traits>& e,
               regex_constants::match_flag_type flags = regex_constants::match_default);

template <class ST, class SA, class charT, class traits>
bool regex_match(const basic_string<charT, ST, SA>& s,
               const basic_regex<charT, traits>& e,
               regex_constants::match_flag_type flags = regex_constants::match_default);

// [7.11.3] Function template regex_search
template <class BidirectionalIterator, class Allocator, class charT, class traits>
bool regex_search(BidirectionalIterator first,
                  BidirectionalIterator last,
                  match_results<BidirectionalIterator, Allocator>& m,
                  const basic_regex<charT, traits>& e,
                  regex_constants::match_flag_type flags = regex_constants::match_default);

template <class BidirectionalIterator, class charT, class traits>
bool regex_search(BidirectionalIterator first,
                  BidirectionalIterator last,
                  const basic_regex<charT, traits>& e,
                  regex_constants::match_flag_type flags = regex_constants::match_default);

template <class charT, class Allocator, class traits>
bool regex_search(const charT* str,
                  match_results<const charT*, Allocator>& m,
                  const basic_regex<charT, traits>& e,
                  regex_constants::match_flag_type flags = regex_constants::match_default);

template <class charT, class traits>
bool regex_search(const charT* str,
                  const basic_regex<charT, traits>& e,
                  regex_constants::match_flag_type flags = regex_constants::match_default);

template <class ST, class SA, class charT, class traits>
bool regex_search(const basic_string<charT, ST, SA>& s,
                  const basic_regex<charT, traits>& e,
                  regex_constants::match_flag_type flags = regex_constants::match_default);

template <class ST, class SA, class Allocator, class charT, class traits>
bool regex_search(const basic_string<charT, ST, SA>& s,
                  match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
                  const basic_regex<charT, traits>& e,
                  regex_constants::match_flag_type flags = regex_constants::match_default);

// [7.11.4] Function template regex_replace
template <class OutputIterator, class BidirectionalIterator, class traits, class charT>
OutputIterator regex_replace(OutputIterator out,
                           BidirectionalIterator first,
                           BidirectionalIterator last,
                           const basic_regex<charT, traits>& e,
                           const basic_string<charT>& fmt,
                           regex_constants::match_flag_type flags = regex_constants::match_default);

template <class traits, class charT>
basic_string<charT> regex_replace(const basic_string<charT>& s,
                                       const basic_regex<charT, traits>& e,
                                       const basic_string<charT>& fmt,
                                       regex_constants::match_flag_type flags = regex_constants::match_default);

// [7.12.1] Class template regex_iterator
template <class BidirectionalIterator,
         class charT = typename iterator_traits<BidirectionalIterator>::value_type,
         class traits = regex_traits<charT> >
class regex_iterator;

typedef regex_iterator<const char*> cregex_iterator;
typedef regex_iterator<const wchar_t*> wcregex_iterator;
typedef regex_iterator<string::const_iterator> sregex_iterator;
typedef regex_iterator<wstring::const_iterator> wsregex_iterator;

// [7.12.2] Class template regex_token_iterator
template <class BidirectionalIterator,
         class charT = typename iterator_traits<BidirectionalIterator>::value_type,
         class traits = regex_traits<charT> >
class regex_token_iterator;

typedef regex_token_iterator<const char*> cregex_token_iterator;
typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;

} // namespace tr1
} // namespace std

Configuration: Boost.Config should (automatically) define the macro BOOST_HAS_TR1_REGEX if your standard library implements this part of TR1.

Standard Conformity: No known problems.


PrevUpHomeNext