From de73da53b512cda43709f20e233a688585e79ca5 Mon Sep 17 00:00:00 2001 From: Jarryd Beck Date: Thu, 18 Sep 2014 15:16:51 +1000 Subject: [PATCH] option regexes --- src/cxxopts.hpp | 9 +++++++++ src/main.cpp | 3 +-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cxxopts.hpp b/src/cxxopts.hpp index 7e3936a..8adef0f 100644 --- a/src/cxxopts.hpp +++ b/src/cxxopts.hpp @@ -1 +1,10 @@ #include + +namespace cxxopts +{ + std::basic_regex option_matcher + ("--([a-zA-Z][-_a-zA-Z]+)(=(.*))?|-([a-zA-Z]+)"); + + std::basic_regex option_specifier + ("(([a-zA-Z]),)?([a-zA-Z][-_a-zA-Z]+)"); +} diff --git a/src/main.cpp b/src/main.cpp index 6f6a6f9..1faeee0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,13 +7,12 @@ int main(int argc, char* argv[]) try { - std::basic_regex options("--([a-zA-Z][-a-zA-Z]+)|-([a-zA-Z]+)"); std::match_results result; for (int i = 1; i < argc; ++i) { 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 << "size = " << result.size() << std::endl; -- libgit2 0.21.4