|
Boost Users : |
Subject: [Boost-users] Newbie Xpressive Help Needed
From: Timothy Sassone (timothy.s.dev_at_[hidden])
Date: 2010-02-24 21:42:19
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.
I'm using Xpressive to "parse" files from a game called Dwarf Fortress, and
one of the lines in the file has a couple places where some information is
printed in a different format, or entirely excluded. The lines are
describing the history of the game, specifically the rulers. For example,
one line might look like this:
*[*] Flichlikus (b.??? d. 3, Reign Began: 1), *** Original Line, Married (d.
91)*
While another would look like this:
*[*] Thufuchrunkin (b.3, Reign Began: 97), Inherited from mother, Married
(d. 160)*
Thus far, I've got it finding the ruler's name, and their birth date (or
"???"). However, 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,
but they're well beyond what I've done with regex before, so I don't really
even know where to begin. How would I go about retrieving the date of death
if it's there, and otherwise skipping it entirely (or better yet, set it to
a default value...)?
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)|"???"));*
*
*
Any help would be much appreciated, and a link to a decent tutorial to help
me with Xpressive in general would be even better.
Thanks!
Tim
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