Good morning, I'm trying to parse a relatively simple pattern across 4 std::strings, extracting whatever the part which matches the pattern into a separate std::string. In an abstracted sense, here is what I want: s1=<string1><consecutive number>, s2=<consecutive number><string2>, s3=<string1><consecutive number>, s4=<consecutive number><string2> Less abstracted: s1="apple 1", s2="2 cheese", s3="apple 3", s4="4 cheese" Actual contents: s1="lxckvjlxcjvlkjlkje xvcjxzlvcj wqrej lxvcjz ljvl;x czvouzxvcu j;ljfds apple 1 xcvljxclvjx oueroi xcvzlkjv; zjx", s2="xzljlkxvc jlkjxzvl jxcvljzx lvjlkj wre 2 cheese", s3="apple 3", s4="kxclvj xcvjlxk jcvljxlck jxcvl 4 cheese" How would I perform this pattern matching? Thanks for all suggestions, Alec Taylor
2011/11/10 Alec Taylor
Good morning,
I'm trying to parse a relatively simple pattern across 4 std::strings, extracting whatever the part which matches the pattern into a separate std::string.
In an abstracted sense, here is what I want: s1=<string1><consecutive number>, s2=<consecutive number><string2>, s3=<string1><consecutive number>, s4=<consecutive number><string2>
Less abstracted: s1="apple 1", s2="2 cheese", s3="apple 3", s4="4 cheese"
Actual contents: s1="lxckvjlxcjvlkjlkje xvcjxzlvcj wqrej lxvcjz ljvl;x czvouzxvcu j;ljfds apple 1 xcvljxclvjx oueroi xcvzlkjv; zjx", s2="xzljlkxvc jlkjxzvl jxcvljzx lvjlkj wre 2 cheese", s3="apple 3", s4="kxclvj xcvjlxk jcvljxlck jxcvl 4 cheese"
How would I perform this pattern matching?
Wouldn't Boost.Regex be more appropriate?
I'm not sure which library to use, or how to use them.
I have been told on freenode though, that what I want goes past the
capabilities of regex. I am skeptical though, which is (in part) why
I'm asking here.
So how could this be done in boost regex?
Thanks :)
On Thu, Nov 10, 2011 at 8:17 AM, TONGARI
2011/11/10 Alec Taylor
Good morning,
I'm trying to parse a relatively simple pattern across 4 std::strings, extracting whatever the part which matches the pattern into a separate std::string.
In an abstracted sense, here is what I want: s1=<string1><consecutive number>, s2=<consecutive number><string2>, s3=<string1><consecutive number>, s4=<consecutive number><string2>
Less abstracted: s1="apple 1", s2="2 cheese", s3="apple 3", s4="4 cheese"
Actual contents: s1="lxckvjlxcjvlkjlkje xvcjxzlvcj wqrej lxvcjz ljvl;x czvouzxvcu j;ljfds apple 1 xcvljxclvjx oueroi xcvzlkjv; zjx", s2="xzljlkxvc jlkjxzvl jxcvljzx lvjlkj wre 2 cheese", s3="apple 3", s4="kxclvj xcvjlxk jcvljxlck jxcvl 4 cheese"
How would I perform this pattern matching?
Wouldn't Boost.Regex be more appropriate?
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I'm trying to parse a relatively simple pattern across 4 std::strings, extracting whatever the part which matches the pattern into a separate std::string.
In an abstracted sense, here is what I want: s1=<string1><consecutive number>, s2=<consecutive number><string2>, s3=<string1><consecutive number>, s4=<consecutive number><string2>
Less abstracted: s1="apple 1", s2="2 cheese", s3="apple 3", s4="4 cheese"
Actual contents: s1="lxckvjlxcjvlkjlkje xvcjxzlvcj wqrej lxvcjz ljvl;x czvouzxvcu j;ljfds apple 1 xcvljxclvjx oueroi xcvzlkjv; zjx", s2="xzljlkxvc jlkjxzvl jxcvljzx lvjlkj wre 2 cheese", s3="apple 3", s4="kxclvj xcvjlxk jcvljxlck jxcvl 4 cheese"
How would I perform this pattern matching?
Use Spirit.
I'm not sure I understand your grammar well, but try the following
trivial sample:
#include
Alec Taylor
I'm trying to parse a relatively simple pattern across 4 std::strings, extracting whatever the part which matches the pattern into a separate std::string.
In an abstracted sense, here is what I want: s1=<string1><consecutive number>, s2=<consecutive number><string2>, s3=<string1><consecutive number>, s4=<consecutive number><string2>
Less abstracted: s1="apple 1", s2="2 cheese", s3="apple 3", s4="4 cheese"
Just to be clear, what do you want in the result string? Without losing data, I believe you could just output: first_num string1 string2
How would I perform this pattern matching?
I'd suggest splitting the responsiblity between regex and your own
code. This lets you use regex for what it's good at, and then use
procedural code for what *it* is good at.
(I ran into this all the time in perl: people would try to do
*everything* in the regex, when it was often much cleaner to do some
of the work in procedural code outside the RE.)
Anyway, find my attempt below.
Best Regards,
Tony
----------------------------------------------------------------------
// compile line:
// g++ -o substr-regex substr-regex.cpp -lboost_regex
#include <iostream>
#include <string>
#include
participants (4)
-
Alec Taylor
-
Anthony Foiani
-
Igor R
-
TONGARI