| Home | Libraries | People | FAQ | More

## Struct template regex_compiler

boost::xpressive::regex_compiler — Class template regex_compiler is a factory for building basic_regex objects from a string.

## Synopsis

    template<typename BidiIter, typename RegexTraits, typename CompilerTraits>
    struct regex_compiler {
      // types
      typedef BidiIter                            iterator_type;
      typedef iterator_value< BidiIter >::type    char_type;
      typedef std::basic_string< char_type >      string_type;
      typedef regex_constants::syntax_option_type flag_type;
      typedef RegexTraits                         traits_type;
      typedef traits_type::char_class_type        char_class_type;
      typedef traits_type::locale_type            locale_type;

      // construct/copy/destruct
      regex_compiler(RegexTraits const & = RegexTraits());

      // public member functions
      locale_type imbue(locale_type) ;
      locale_type getloc() const;
      basic_regex< BidiIter >
      compile(string_type, flag_type = regex_constants::ECMAScript) ;
    };

## Description

Class template regex_compiler is used to construct a basic_regex object from a string. The string should contain a valid regular expression. You can imbue a regex_compiler object with a locale, after which all basic_regex objects created with that regex_compiler object will use that locale. After creating a regex_compiler object, and optionally imbueing it with a locale, you can call the compile() method to construct a basic_regex object, passing it the string representing the regular expression. You can call compile() multiple times on the same regex_compiler object. Two basic_regex objects compiled from the same string will have different regex_id's.

### `regex_compiler` construct/copy/destruct

1.     regex_compiler(RegexTraits const & traits = RegexTraits());

### `regex_compiler` public member functions

1.     locale_type imbue(locale_type loc) ;

   Specify the locale to be used by a regex_compiler.

   Parameters: |
   `loc` | The locale that this regex_compiler should use.
   Returns: | The previous locale.

2.     locale_type getloc() const;

   Get the locale used by a regex_compiler.

3.     basic_regex< BidiIter >
       compile(string_type pat, flag_type flags = regex_constants::ECMAScript) ;

   Builds a basic_regex object from a std::string.

   Parameters: |
   `flags` | Optional bitmask that determines how the pat string is interpreted. (See syntax_option_type.)
   `pat` | A std::string containing the regular expression pattern.
   Requires: | The std::string pat contains a valid string-based representation of a regular expression.
   Returns: | A basic_regex object corresponding to the regular expression represented by the string.
   Throws: | regex_error when the string has invalid regular expression syntax.

| Copyright © 2003, 2004 Eric Niebler