C ++ 14、234 229バイト
編集:の代わりに古いスタイルの宣言を使用して5バイトを削減しますauto。
私は勝者がすでに選ばれていることを知っています、そして、これはこれまでの最も長い提出であることを知っています、しかし、私はC ++ソリューションを投稿しなければなりませんでした。
正直に言うと、私はそれがどれほど短いか(C ++の測定によって)に非常に満足しており、これよりも短くなることはないと確信しています(1つの発言で、以下を参照してください) 。また、C ++ 11/14の新機能の非常に優れたコレクションです。
ここにはサードパーティのライブラリはありません。標準ライブラリのみが使用されます。
解決策はラムダ関数の形式です:
[](auto&s){sregex_iterator e;auto r="{"s;for(auto&t:{"y","mo","d","h","mi","s"}){int a=0;regex g("-?\\d+ *"s+t);decltype(e)i(begin(s),end(s),g);for_each(i,e,[&](auto&b){a+=stoi(b.str());});r+=to_string(a)+"|";}r.back()='}';s=r;};
ゴルフをしていない:
[](auto&s)
{
    sregex_iterator e;
    auto r="{"s;
    for(auto&t:{"y","mo","d","h","mi","s"})
    {
        int a=0;
        regex g("-?\\d+\\s*"s+t);
        decltype(e)i(begin(s),end(s),g);
        for_each(i,e,[&](auto&b)
        {
            a+=stoi(b.str());
        });
        r+=to_string(a)+"|";
    }
    r.back()='}';
    s=r;
}
何らかの理由で、私は書く必要がありました
regex g("-?\\d+\\s*"s+t);
decltype(e)i(begin(s),end(s),g);
ただの代わりに
decltype(e)i(begin(s),end(s),regex("-?\\d+\\s*"s+t));
なぜなら、一時オブジェクトを渡すと、反復子は1つの一致だけを返すからです。これは私には正しくないと思われるので、GCCの正規表現の実装に問題があるのではないかと思います。
完全なテストファイル(GCC 4.9.2でコンパイル済み-std=c++14):
#include <iostream>
#include <string>
#include <regex>
using namespace std;
int main()
{
    string arr[] = {"1 year 2 months 3 seconds",
                    "-2 day 5 year 8months",
                    "3day 9     years 4 seconds -5 minute 4 years 4 years -3seconds"};
    for_each(begin(arr), end(arr), [](auto&s){sregex_iterator e;auto r="{"s;for(auto&t:{"y","mo","d","h","mi","s"}){int a=0;auto g=regex("-?\\d+ *"s+t);decltype(e)i(begin(s),end(s),g);for_each(i,e,[&](auto&b){a+=stoi(b.str());});r+=to_string(a)+"|";}r.back()='}';s=r;});
    for(auto &s : arr) {cout << s << endl;}
}
出力:
{1|2|0|0|0|3}
{5|8|-2|0|0|0}
{17|0|3|0|-5|1}