Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost::Split using whole string as delimiter

I would like to know if there is a method using boost::split to split a string using whole strings as a delimiter. For example:

str = "xxaxxxxabcxxxxbxxxcxxx"

is there a method to split this string using "abc" as a a delimiter? Therefore returning:

Results would be the string "xxaxxxx" and "xxxxbxxxcxxx".

I am aware of boost::split using the "is_any_of" predicate, however invoking is_any_of("abc") would result in splitting the string at the single character 'a', 'b', and 'c' as well, which is not what I want.

like image 779
andre Avatar asked Sep 15 '11 20:09

andre


1 Answers

Yes there is a way (this is a way I know, maybe there is a better way) Use boost::algorithm::split_regex to split character sequences where delimiters are regular expressions.

Example:

vector< string > result;
boost::algorithm::split_regex( result, str, regex( "^((?!abc)*abc(?!abc)*)*$" ) ) ;
copy( result.begin(), result.end(), ostream_iterator<string>( cout, "\n" ) ) ;
like image 91
Mythli Avatar answered Sep 20 '22 06:09

Mythli