boost

regex [cxx][programming]

boost::regexPerl みたいな感じで正規表現を使わせてくれるライブラリ。

#include <iostream>
#include <boost/regex.hpp>

int main() {
  using namespace std;
  using boost::regex;
  using boost::sregex_token_iterator;
  string s("a/b c/d e/f");
  sregex_token_iterator
    i(s.begin(), s.end(), regex("\\s"), -1),
    end;
  for ( ; i != end; ++i ) {
    string w(i->first, i->second);
    cout << w << endl;
    sregex_token_iterator
      j(w.begin(), w.end(), regex("/"), -1);
    for ( ; j != end; ++j ) {
      cout << string(j->first, j->second) << endl;
    }
  }
}

wregex, wsregex_token_iterator を使うと、とりあえず多バイト文字が扱える。

u32regex, u32regex_token_iterator を使うと、Unicode の文字クラスが使える(ICU必要)。
http://www.boost.org/libs/regex/doc/icu_strings.html