Pattern matching in C++

A

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 czvouzxvcuj;ljfds apple 1 xcvljxclvjx oueroi xcvzlkjv; zjx",
s2="xzljlkxvcjlkjxzvl jxcvljzx lvjlkj wre 2 cheese",
s3="apple 3",
s4="kxclvj xcvjlxk jcvljxlck jxcvl 4 cheese"

How would I perform this pattern matching, and what libraries should I use?

Thanks for all suggestions,

Alec Taylor
 
M

Marc

Alec said:
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 czvouzxvcuj;ljfds apple 1 xcvljxclvjx oueroi xcvzlkjv; zjx",
s2="xzljlkxvcjlkjxzvl jxcvljzx lvjlkj wre 2 cheese",
s3="apple 3",
s4="kxclvj xcvjlxk jcvljxlck jxcvl 4 cheese"

How would I perform this pattern matching, and what libraries should I use?

The standard library should have what you need in <regex>, or if you
have an older compiler/library: Boost.Regex.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top