Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
2.67/5 (3 votes)
See more:
I need help!

I want to know how to match the string input by the user.
Example if the user input: aabbaa then it was match
otherwise if the user input: aabaa then it was mismatch.

Can you give some idea or sample code how to do it.
Posted
Comments
Sergey Alexandrovich Kryukov 15-Aug-12 20:37pm    
Showing the sample is not enough: it might be not representative; you understand it because you have a pattern in your mind, but others do not. Nothing can be a substitute for a formal definition. I can only give a general answer.
--SA
ChineseGuy 16-Aug-12 6:07am    
why don'you use strcmp(str1,str2)??

Please see my comment to the question: it is not fully formulated. However, for a wide class of problems, Regular Expressions can provide a comprehensive solution. Please see:
http://en.wikipedia.org/wiki/Regular_expression[^],
http://www.regular-expressions.info/reference.html/[^],
http://www.regular-expressions.info/refadv.html[^],
http://en.wikipedia.org/wiki/Wikipedia:AutoWikiBrowser/Regular_expression[^].

You can always find a suitable Regular Expression Engine. Please see:
http://code.google.com/p/regen/[^],
http://www.drdobbs.com/cpp/regular-expressions-in-c/184404797[^],
http://freecode.com/projects/cpp_regex[^].

To find more, try this: http://bit.ly/NqDGfC[^].

[EDIT #1]

When you have an engine, using it for complex problems can be a whole art. Look for Expresso. This is a tool which is very helpful:
http://www.ultrapico.com/Expresso.htm[^].

[EDIT #2]

Expresso also has a very good manual on using Regular Expressions.

[EDIT #3]

Please see also this CodeProject article:
Using Regular Expressions in MFC[^].

[EDIT #4]

As pastopristi correctly noted below, it could be even as simple as '==' operator of std::string… :-)

The problem is that the problem is not strictly formulated. :-(

—SA
 
Share this answer
 
v6
Comments
pasztorpisti 16-Aug-12 4:22am    
+5, however the question brought operator==() to my mind... :-)
The google stuff is also pretty nice :D
Sergey Alexandrovich Kryukov 16-Aug-12 4:50am    
Me too... :-)
Thank you for your opinion on the quality of the library (and voting).
(I never tried those libraries. Started to use Regular Expression with 3rd party unit in Delphi (still using my own text editor written with it), worked with JavaScript and stupid PHP, mostly before .NET...)
--SA
pasztorpisti 16-Aug-12 6:02am    
The wiki page is excellent source to get the grasp about regex in general. I myself use PCRE from C and C++ (mentioned in the linked MFC article). Its source is a bit bloaty but its a mature and reliable library. I usually keep it separated from my project in a static lib instead of putting it directly to my project. If I need a simple 'drop in' codepiece I usually use a modified version of Henry Spencer's legendary regex lib: http://www.arglist.com/regex/
The linked regen library is also very interesting, I'm curious about its stability and architecture dependent issues because of the native code generator.
Sergey Alexandrovich Kryukov 16-Aug-12 12:37pm    
Again, thank you very much for sharing your assessments.
--SA
BillW33 16-Aug-12 9:10am    
Regular expressions are great! This is also a good answer, +5 :)
Take a look at class std::string, or CString. You can find plenty of samples in internet

jkchan
http://cgmath.blogspot.com
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 16-Aug-12 4:55am    
Well, I up-voted it by 4, but who knows? The question is too vague... Perhaps my solution is somewhat of overkill...
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900