C++/STL string: How to mimic regex like function with wildcards?

↘锁芯ラ 提交于 2019-12-24 04:58:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!