Boost logo

Boost Users :

From: Poulson, Shawn (shawn.poulson_at_[hidden])
Date: 2002-07-24 09:43:28


Hello all,

I got Regex to compile and link into a project using MSVC6. My problem is in trying to implementing a command line parsing regexp that handles quoted strings. I have code that will selectively match quoted strings but somehow ignores non-quoted strings. The code fragment is below. I've read over Mastering Regular Expressions and some Perl Cookbook stuff but nothing works straight out of the book. Any tips?

The code below finds all three parameters (in the spec var), but has no match for 'parm1'.

Any help is certainly appreciated. Thanks.

----- 8< ----- 8< -----

   boost::regex exp(
      "\"(?:(\\\\.|[^\"])*)\"[:space:]*"
      "|"
      "([^[:space:]]+)[:space:]*"
   );
   std::string str = "parm1 \"parm2 parm3\" \"parm4 \\\"yo\\\"\"";
   std::string::const_iterator start = str.begin(), end = str.end();
   boost::match_results<std::string::const_iterator> what;
   unsigned int flags = boost::match_default;

   while (boost::regex_search(start, end, what, exp, flags)) {
      std::string spec(what[0].first, what[0].second-what[0].first);
      std::string match(what[1].first, what[1].second-what[1].first);
      start = what[0].second;
   }

----- 8< ----- 8< -----

---
Shawn Poulson

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net