![data toolbar regex filter data toolbar regex filter](https://files.realpython.com/media/Regular-Expressions-Regexes-in-Python-Part-1_Watermarked_1.ffa77de784ec.jpg)
This stream is used when you want to read data with filters. Thus, the example displays 5 and 0.Įxample 34.8 uses the stream boost::iostreams::filtering_istream in addition to boost::iostreams::filtering_ostream. It returns 0 if an incorrect filter type is passed as a template parameter.Įxample 34.7 writes five characters to the stream. component() returns a pointer to the filter. Because component() is a template, the type of the filter must be passed as a template parameter. The index of the respective filter must be passed as a parameter. This class provides the member functions characters() and lines().īoost::iostreams::filtering_stream provides the member function component() to access a filter. However, you can complete a stream if you add a device with push() after a call to pop().Įxample 34.7 uses the filter boost::iostreams::counter, which counts characters and lines. Please note that you must not use a stream that isn’t connected with a device. Without the call to pop(), boost::iostreams::regex_filter won’t process any data and won’t forward data to the device. Example 34.6 calls pop() after “ Boost” has been written to the stream. This happens when the device is removed from the stream with the member function pop(). That’s why boost::iostreams::regex_filter starts filtering only after a write operation is complete and all data is available. The filter boost::iostreams::regex_filter can’t process data character by character because regular expressions need to look at character groups.
![data toolbar regex filter data toolbar regex filter](https://www.elastic.co/guide/en/beats/packetbeat/current/images/kibana-filters.png)
You can pass one or more filters, but once a device has been passed, the stream is complete, and you must not call push() again. The filter(s) must be passed before the device the order is important. This class provides a member function push(), which the filter and the device are passed to. The filter and the device are connected with the stream boost::iostreams::filtering_ostream. The filter will match one or more consecutive instances of the letter “ o” in “ Boost,” but not zero instances. The example replaces “ Boost” with “ C++”. The format string specifies what the characters should be replaced with. The regular expression describes what to replace. The filter expects a regular expression and a format string. The data is sent through a filter of type boost::iostreams::regex_filter, which replaces characters. Os.push(regex_filter) Įxample 34.6 uses the device boost::iostreams::array_sink to write data to an array.