C 或 C++ 是吗?有标准的正则表达式库吗?
是吗?如果是,我在哪里可以获得它的文档...如果不是,那么哪个是最好的选择?
Does it? If yes, where can I get the documentation for it... if not, then which would be the best alternative?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
C++11 现在终于有了一个 标准正则表达式库 - std: :正则表达式。
如果您无法访问 C++11 实现,一个好的替代方案可能是 增强正则表达式。它并不完全等同于 std::regex (例如 “empty() " 方法不在 std::regex 中),但它仍然是 C++ 的一个非常成熟的正则表达式实现。
C++11 now finally does have a standard regex library - std::regex.
If you do not have access to a C++11 implementation, a good alternative could be boost regex. It isn't completely equivalent to std::regex (e.g. the "empty()" method is not in the std::regex) but it's a very mature regex implementation for C++ none the less.
在类 UNIX 系统下,您可以使用 POSIX 正则表达式函数。
Under UNIX-like systems you can use POSIX regex functions.
Microsoft Visual C++ 2008 Feature Pack 1(现已纳入 Visual Studio 2008 Service Pack 1)包含“官方”TR1 reg ex 类型的实现。让自己崩溃:-)
The Microsoft Visual C++ 2008 Feature Pack 1 (now rolled into the Visual Studio 2008 Service Pack 1) contains a implementation of the 'official' TR1 reg ex types. Knock yourself out :-)
检查 boost regex 库。它应该成为 C++0x 标准的一部分。
Check the boost regex library. It should become part of the standard with C++0x.
如果您所说的“标准”是指与编译器捆绑在一起,那么就不是。但大多数捆绑正则表达式扩展的其他语言都使用相当标准的
c
实现。例如 PCRE - Perl 兼容正则表达式 和 C 库具有 POSIX 正则表达式支持(请参阅 手册页)。If by standard you mean bundled with compiler, then not. But most of the other languages that bundle regex extension use pretty standard
c
implementations. E.g. PCRE - Perl Compatible Regular Expression and C libraries have POSIX regex support (see man page).正则表达式是 C++ 扩展 TR1 的一部分。 Dinkumware、Visual Studio 和其他公司已经实现了这一点。
请参阅
C++ TR1 正则表达式快速入门
Regular Expressions are part of the C++ extension TR1. Dinkumware, visual studio and others already have implemented this.
See
Quick Start for C++ TR1 Regular Expressions
Visual C++ 2008 Feature Pack
来自 Trolltech 的 Qt 也有一个正则表达式实现,我发现它非常易于使用。但是,如果您不打算将 Qt 用于其他用途,我会使用 Boost.Regex,因为您可能也可以将 Boost 用于其他目的。
Qt, from Trolltech, also has a regex implementation which I find very easy to use. However, if you are not planning of using Qt for anything else I would use Boost.Regex as you probably would be good off using Boost for other purposes as well.
标准 ISO/IEC 14882:2011 编程语言 C++ 将 regex 类描述为 C++ 库的一部分,该类深受成熟的 Boost 库的影响。
奇怪的是,截至 2013 年 1 月,编译器对该标准的遵守情况仍然参差不齐,例如 GNU 编译器套件中流行的 C++ 编译器不支持/不遵守该标准的这一部分。
因此,最好在此时使用 Boost,直到编译器支持达到合规性。
The standard ISO/IEC 14882:2011 Programming Language C++ describes a regex class as part of C++'s library, which is heavily influenced by the mature Boost library.
Curiously, as of January 2013, compilers' compliance with this standard is still spotty, e.g. the GNU compiler suite's popular C++ compiler does not support/comply with this part of the standard.
For that reason, it's best to use Boost at this point in time until compiler support reaches compliance.
+1 PCRE - Perl 兼容正则表达式 ,我记得使用 Mircosoft 的 GRETA 也是如此。
+1 for PCRE - Perl Compatible Regular Expression , I remembered using Mircosoft's GRETA as well.