boostの正規表現ライブラリ boost::regex を使ったサンプルです。
boost::regex は以下のコマンドでインストールすることができます。

$ sudo aptitude install libboost-regex-dev

サンプル regextest.cpp を準備します。これは正規表現リプレイサです。

#include <iostream>

#include <string>

#include <boost/regex.hpp>

// usage: a.out pattern replace-to

using namespace std;

int main(int c, char** v)
{
  if (c != 3) return 1;

boost::regex ex(v[1]); // 正規表現オブジェクト
  char buf[256];         // 読み取り用のバッファ

while (cin.getline(buf, sizeof(buf)))
    cout << boost::regex_replace(string(buf), ex, v[2]) << endl;

return 0;
}

ビルドします。

$ g++ -lboost_regex regextest.cpp

実行します。

#先頭の二文字を入れ替える

$ ls / | ./a.out '^(.)(.)' '$2$1'
ibn
obot
edv
tec
ohme
niitrd.img
ilb
olst+found
nmt
pot
rpoc
orot
bsin
eslinux
rsv
yss
mtp
sur
avr
mvlinuz

簡単ですね。