C++/STL 字符串:如何使用通配符模拟正则表达式之类的函数?

发布于 2024-08-25 06:33:33 字数 334 浏览 4 评论 0原文

我想使用通配符比较 4 个字符串。

例如:

std::string wildcards[]=
{"H?  ", "RH? ", "H[0-5]  "};
/*in the last one I need to check if string is "H0  ",..., and "H5  " */

是否可以只用STL来实现?

谢谢, 阿曼.

编辑:

我们可以在没有 boost.regex 的情况下做到这一点吗?
或者我应该向我的项目添加另一个库依赖项?:)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

我的黑色迷你裙 2024-09-01 06:33:33

不 - 你需要 boost::regex

No - you need boost::regex

靑春怀旧 2024-09-01 06:33:33

正则表达式就是为这类事情而设计的。我可以理解您不愿意避免依赖,但在这种情况下,这可能是合理的。

您可以检查您的 C++ 编译器,看看它是否包含任何内置正则表达式库。例如,Microsoft 包含 CAtlRegExp

除此之外,您的问题看起来编写自定义代码并不难。

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.

初熏 2024-09-01 06:33:33

您可以在不引入新的库依赖项的情况下完成此操作,但这样做最终您需要自己编写正则表达式引擎(或至少是正则表达式引擎的子集)。

您有什么原因不想为此使用库吗?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文