option regexes

This commit is contained in:
Jarryd Beck 2014-09-18 15:16:51 +10:00
parent 2deb5d87fb
commit de73da53b5
2 changed files with 10 additions and 2 deletions

View File

@ -1 +1,10 @@
#include <regex> #include <regex>
namespace cxxopts
{
std::basic_regex<char> option_matcher
("--([a-zA-Z][-_a-zA-Z]+)(=(.*))?|-([a-zA-Z]+)");
std::basic_regex<char> option_specifier
("(([a-zA-Z]),)?([a-zA-Z][-_a-zA-Z]+)");
}

View File

@ -7,13 +7,12 @@ int main(int argc, char* argv[])
try try
{ {
std::basic_regex<char> options("--([a-zA-Z][-a-zA-Z]+)|-([a-zA-Z]+)");
std::match_results<const char*> result; std::match_results<const char*> result;
for (int i = 1; i < argc; ++i) for (int i = 1; i < argc; ++i)
{ {
std::cout << "Argument " << i << std::endl; std::cout << "Argument " << i << std::endl;
std::regex_match(argv[i], result, options); std::regex_match(argv[i], result, cxxopts::option_matcher);
std::cout << "empty = " << result.empty() << std::endl; std::cout << "empty = " << result.empty() << std::endl;
std::cout << "size = " << result.size() << std::endl; std::cout << "size = " << result.size() << std::endl;