Boost logo

Boost :

Subject: [boost] [xpressive] regex_token_iterator - bug, feature, misunderstanding query?
From: Michael Goldshteyn (mgoldshteyn_at_[hidden])
Date: 2008-12-03 11:50:01

OK, so I want to use the sregex_token_iterator functionality to split a data
string. The data string contains:


The delimiter is the forward slash and I do want empty strings. I expect to


What I actually get is:


The empty string after {c}, which I expect because the data string ended in
a forward slash, is missing. What do I have to do to get the empty string
after {c} if the data string ends in a forward slash?

The code is as follows:

#include <iostream>
#include <string>
#include <boost/xpressive/xpressive.hpp>
#include <boost/xpressive/regex_token_iterator.hpp>
int main(int argc, char *argv[])
  // Split the path
  using namespace boost::xpressive; // For simplicity
  sregex levelSplitter(as_xpr('/'));
  std::string nodePath("/a/b//c/");
  sregex_token_iterator end;
  for (sregex_token_iterator iCur=begin;iCur!=end;++iCur)
    std::cout << '{' << *iCur << '}';
  std::cout << std::endl;
 return 0;
Michael Goldshteyn

Boost list run by bdawes at, gregod at, cpdaniel at, john at