Consider the code:
regex boundary{ "\\s*\\b\\s*" };
string test = "foo bar\t baz-floop";
auto begin = sregex_token_iterator(test.begin(), test.end(), boundary, -1);
for (auto i = begin; i != sregex_token_iterator{}; i++) {
cout << *i << endl;
}
The code was adapted from other answer and was meant to split the string by regex. The result of calling this (on VC++ 16.2.3) are:
oo
ar
az
loop
How can I correct the code, so that the first letter of matches are not deleted? I can't change the regex itself. Moreover, the analogous code in Java seems to work according to my expactations:
Pattern boundary = Pattern.compile("\\s*\\b\\s*");
String test = "foo bar\t baz-floop";
String[] results = boundary.split(test);
for (String result : results) {
System.out.println(result);
}