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?

2

1 Answer 1

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)?

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for helping me solve this problem. I really remiss. :)
i solved it using "\\" slash trick const std::regex reg_off_p("\\+[0-9A-F]{2}");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.