Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-02-05 19:50:11


Bob Kline wrote:

> #include <boost/regex.hpp>
> int main() {
> boost::wregex e(L"^[^\\s]( ?([^\\s]+ ?)*[^\\s])?$");
> boost::wcmatch m;
> boost::regex_match(L"codeine phosphate ", m, e);
> return 0;
> }

[...]

> I'm pretty sure that the expression is boiled down to the least
> ambiguous form (without changing the semantics). In plain English,
> it's looking for strings that have no leading or trailing whitespace,
> and for which any internal whitespace runs are comprised solely of a
> single blank character.

I've no idea which part of the regexp causes the library to give up, but
isn't there a much simpler reformulation:

  ^[^\s]+( [^\s]+)*$

that achieves the same result? In addition to running at all, it should also
run much faster. :-) Unless I've missed something, of course.


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