2

I wrote the following code for parsing command line arguments, using Visual C++ 2012. These command-line parameters have traditional GNU style (--option).

void parseCmdLines(int argc, wchar_t* argv[]) {
  for (auto i = 1; i < argc; ++i) {
    std::wstring arg(argv[i]);
    // I hope it can match the L"--config=../etc/my.conf"
    std::wregex regex(L"--config=(+*)");
    std::wsmatch match;
    std::regex_match(arg, match, regex);

    // TODO: ...
}

Unfortunately, when I run this program, I met an exception. The description of the exception is as follows:

Microsoft C++ exception: std::regex_error at memory location 0x23F090.

How can I solve this problem?

R. Martinho Fernandes
  • 228,013
  • 71
  • 433
  • 510
chee
  • 25
  • 1
  • 4

1 Answers1

5

It's likely that your problem is with +*.

+ means one or more of what appears before it and * means zero or more of what appears before it (since there is a ( before the +, it shouldn't work, since this merely means the start of a group, and for the + before the *, you can't really say "zero or more of one or more").

Did you maybe mean .* (i.e. zero or more of anything) or .+ (i.e. one or more of anything)?

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138