Boost logo

Boost Users :

Subject: Re: [Boost-users] Regex problem: cannot parse terms containing OR
From: John Maddock (john_at_[hidden])
Date: 2009-09-27 05:38:21


----- Original Message -----
From: "Ramon F Herrera" <ramon_at_[hidden]>
To: <boost-users_at_[hidden]>
Sent: Sunday, September 27, 2009 12:04 AM
Subject: [Boost-users] Regex problem: cannot parse terms containing OR

>
> I have been able to parse stuff more complicated than this, but now I am
> stuck with something seemingly simpler.
>
> The expression being parsed is the common sequence:
>
> 1,2-5,7,8-11
>
> Question 1: Notice my approach. I first match the whole expression, with
> "regex_match", to make sure that it is valid (that works great). Next, I
> use "regex_iterator" to break down the parts. Is that good practice? Am
> I being inefficient/redundant?

It depends :-) If it's fast enough it's good enough, and I've often done
similar things (it's easy to understand compared to a more "sophisticated"
approach too).

> Question 2: My code below only extracts "range terms" ("x-y"), for some
> reason I cannot extract "number terms".

You need something like: \\d+(?:\\s*-\\s*\\d+)? to match a "digit or range".

HTH, John.


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