简体   繁体   中英

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 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?:)

使用Boost.Regex

否-您需要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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM