On Fri, Oct 25, 2002 at 10:54:54AM +0200, Jean-Marc Lasgouttes wrote:
> Just that. I am not even sure it supports both syntaxes. I think it
> currently breaks whenever there is a $ in the text, and I think it is
> because boost is not prepared to see regexps like "*}*" and just dies.

The following seems to work, although I am not really happy with it.
There must be a way without searching twice and re-building the full line
everytime....


#include "boost/regex.hpp"

#include <string>
#include <iostream>
#include <cstdlib>

using namespace std;
using namespace boost;

int main(int argc, char * argv[])
{
        regex ex("(.*)\\$\\{(.*)\\}(.*)");
        match_results<string::const_iterator> match;

        string line = argv[1];
        while (regex_match(line, match, ex)) {
                line =
                        string(match[1]) +
                        regex_merge(line, ex, getenv(string(match[2]).c_str())) +
                        string(match[3]);
        }
        cout << "res: '" << line << "'" << endl;

        return 0;       
}

Reply via email to