问题
I would like to compare 4 character string using wildcards.
For example:
std::string wildcards[]=
{"H? ", "RH? ", "H[0-5] "};
/*in the last one I need to check if string is "H0 ",..., and "H5 " */
Is it possible to manage to realize only by STL?
Thanks, Arman.
EDIT:
Can we do it without boost.regex?
Or should I add yet another library dependences to my project?:)
回答1:
Use Boost.Regex
回答2:
No - you need boost::regex
回答3:
Regular expressions were made for this sort of thing. I can understand your reluctance to avoid a dependency, but in this case it's probably justified.
You might check your C++ compiler to see if it includes any built-in regular expression library. For example, Microsoft includes CAtlRegExp.
Barring that, your problem doesn't look too difficult to write custom code for.
回答4:
You can do it without introducing a new library dependency, but to do so you'd end up writing a regular expression engine yourself (or at least a subset of one).
Is there some reason you don't want to use a library for this?
来源:https://stackoverflow.com/questions/2471651/c-stl-string-how-to-mimic-regex-like-function-with-wildcards