Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Pattern matching in C++

Reply
Thread Tools

Pattern matching in C++

 
 
Alec Taylor
Guest
Posts: n/a
 
      11-09-2011
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
 
Reply With Quote
 
 
 
 
Marc
Guest
Posts: n/a
 
      11-09-2011
Alec Taylor wrote:

> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Pattern matching. Matching multiple lines from while reading from a file. Bobby Chamness Perl Misc 2 05-03-2007 06:02 PM
Matching neighbouring words of a pattern using Regex CV Perl 2 08-31-2004 12:27 AM
Pattern matching : not matching problem Marc Bissonnette Perl Misc 9 01-13-2004 05:52 PM
Pattern matching help! grep emails from file! danpres2k Perl 3 08-25-2003 02:47 PM
A newbie question on pattern matching DelphiDude Perl 3 07-26-2003 12:54 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57