Boost logo

Boost Users :

Subject: [Boost-users] How to judge matched rule when looping with sregex_token_iterator in boost.xpressive?
From: Li Dong (dongli_at_[hidden])
Date: 2014-07-02 23:47:15


Dear all,

I would like to use boost.xpressive to parse some string like “a+b:c”, and I wrote the following snippet:

sregex reOp = as_xpr('+') | '-' | '*' | '/';
sregex reDelim = as_xpr(':');
sregex reField = +_w;
sregex reSimpleToken = reOp | reDelim | reField;

string str = "a+b:c";

sregex_token_iterator cur(str.begin(), str.end(), reSimpleToken), end;

for (; cur != end; ++cur) {
    cout << *cur << endl;
}

which will print:

a
+
b
:
c

but I would also want to know which rule is matched for the sequent operations, for example ‘a’, ‘b’ and ‘c' are matched by reField, and ‘+’ is matched by ‘reOp’. I am very new to boost.xpressive, so if this is not the good way, correct me please. Any help is appreciated!

Best,
Li



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