Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6324911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:47:42+00:00 2026-05-24T16:47:42+00:00

I am a using a boost regex on a boost circular buffer and would

  • 0

I am a using a boost regex on a boost circular buffer and would like to “remember” positions where matches occur, what’s the best way to do this? I tried the code below, but “end” seems to store the same values all the time! When I try to traverse from a previous “end” to the most recent “end” for example, it doesn’t work!

  boost::circular_buffer<char> cb(2048);
  typedef boost::circular_buffer<char>::iterator  ccb_iterator;
  boost::circular_buffer<ccb_iterator> cbi(4); 

  //just fill the whole cbi with cb.begin()  
  cbi.push_back(cb.begin());
  cbi.pushback(cb.begin());
  cbi.pushback(cb.begin());
  cbi.pushback(cb.begin());


 typedef regex_iterator<circular_buffer<char>::iterator> circular_regex_iterator;

 while (1)
{
  //insert new data in circular buffer (omitted)
  //basically reads data from file and pushes it back to cb

  boost::circular_buffer<char>::iterator    start,end;  

 circular_regex_iterator regexItr(
        cb.begin(), 
        cb.end() , 
         re, //expression of the regular expression
         boost::match_default | boost::match_partial); 
    circular_regex_iterator last;

    while(regexItr != last)
    {

            if((*regexItr)[0].matched == false)
           {
               //partial match      
               break;
            }
        else
        {
           // full match:
           start = (*regexItr)[0].first;
           end = (*regexItr)[0].second; 

             //I want to store these "end" positions to to use later so that I can 
             //traverse the buffer between these positions (matches).  

            //cbi stores positions of these matches, but this does not seem to work!                 
             cbi.push_back(end);    

            //for example, cbi[2] --> cbi[3] traversal works only first time this 
            //loop is run!
        }

        ++regexItr;
    }

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:47:43+00:00Added an answer on May 24, 2026 at 4:47 pm

    This isn’t quite as much an answer as an attempt to reconstruct what you’re doing. I’m making a simple circular buffer initialized from a string, and I traverse regex matches through that buffer and print the matched ranges. All seems to work fine.

    I would not recommend storing the ranges themselves in a circular buffer; or at the very least the ranges should be stored in pairs.

    Here’s my test code:

    #include <iostream>
    #include <string>
    #include <boost/circular_buffer.hpp>
    #include <boost/regex.hpp>
    #include "prettyprint.hpp"
    
    typedef boost::circular_buffer<char> cb_char;
    typedef boost::regex_iterator<cb_char::iterator> cb_char_regex_it;
    
    int main()
    {
      std::string sample = "Hello 12 Worlds 34 ! 56";
      cb_char cbc(8, sample.begin(), sample.end());
    
      std::cout << cbc << std::endl;    // (*)
    
      boost::regex expression("\\d+");  // just match numbers
    
      for (cb_char_regex_it m2, m1(cbc.begin(), cbc.end(), expression); m1 != m2; ++m1)
      {
        const auto & mr = *m1;
        std::cout << "--> " << mr << ", range ["
                  << std::distance(cbc.begin(), mr[0].first) << ", "
                  << std::distance(cbc.begin(), mr[0].second) << "]" << std::endl;
      }
    }
    

    (This uses the pretty printer to print the raw circular buffer; you can remove the line marked (*).)


    Update: Here’s a possible way to store the matches:

    typedef std::pair<std::size_t, std::size_t> match_range;
    typedef std::vector<match_range>            match_ranges;
    
    /* ... as before ... */
    
      match_ranges ranges;
    
      for (cb_char_regex_it m2, m1(cbc.begin(), cbc.end(), expression); m1 != m2; ++m1)
      {
        const auto & mr = *m1;
    
        ranges.push_back(match_range(std::distance(cbc.begin(), mr[0].first), std::distance(cbc.begin(), mr[0].second)));
    
        std::cout << "--> " << mr << ", range " << ranges.back() << std::endl;
      }
    
      std::cout << "All matching ranges: " << ranges << std::endl;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What might be the best way to start programming using boost lambda libraries.
Is there a similar way to write this regex without using possessive quantifiers (ie
I have just started using Boost 1.36. These libraries would be very useful in
Since I have started using this site, I keep hearing about the Boost library.
I just started using Boost::regex today and am quite a novice in Regular Expressions
I'm trying to get all words inside a string using Boost::regex in C++. Here's
I'm just getting my head around regular expressions, and I'm using the Boost Regex
include #include <algorithm> #include<boost/algorithm/string.hpp> #include<boost/regex.hpp> using namespace std; using namespace boost; string _getBasehtttp(string url)
include #include <fstream> #include <string> #include<string> #include<boost/algorithm/string.hpp> #include<boost/regex.hpp> #include <boost/algorithm/string/trim.hpp> using namespace std; using
I'm using Boost.Range to pass around some data and a container class for this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.