|
Boost Users : |
Subject: Re: [Boost-users] Newbie Xpressive Help Needed
From: Eric Niebler (eric_at_[hidden])
Date: 2010-02-24 22:42:22
On 2/25/2010 1:42 PM, Timothy Sassone wrote:
> I'm new to both boost and Xpressive, but I've worked with regex before.
> I've been able figure most of it out from the Xpressive user guide,
> but I'm having some trouble with a particular expression.
<snip>
> since the date of death is sometimes completely
> absent, I need some way to get the number if it's there, and skip it
> otherwise. From what I understand, I'll need to use the lookahead or
> lookbehind constructs
<snip>
It's much simpler than that. You want an optional quantifier.
> Here's what I'm using to parse up through the date of birth...
> mark_tag RU_Name(1), RU_Birth(2), RU_Death(3), RU_ReignBegin(4),
> RU_Line(5), RU_Married(6);
> sregex Reg_Ruler = " [*] " >> ( RU_Name = +(+_w|_s) ) >> "(b." >>
> (RU_Birth = (+(_d)|"???"));
... >> !("d." >> (RU_Death = +_d)) >> ...
The '!' makes the sub-expression match 1 or 0 times.
After the regex_match, you can check the match_results to see if
RU_Death participated in the match like:
if (results[RU_Death].matched)
// ... results[RU_Death] contains a date of death.
> Any help would be much appreciated, and a link to a decent tutorial to
> help me with Xpressive in general would be even better.
The decent tutorial on xpressive is the users' guide. Or does that not
qualify as "decent"? Ahem. ;-)
-- Eric Niebler BoostPro Computing http://www.boostpro.com
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