C++/STL string: How to mimic regex like function with wildcards?
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 che开发者_开发知识库ck 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?:)Use Boost.Regex
No - you need boost::regex
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.
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?
精彩评论