Does C or C++ have a standard regex library?

限于喜欢 提交于 2019-12-02 22:43:23
Joris Timmermans

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.

Under UNIX-like systems you can use POSIX regex functions.

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

Check the boost regex library. It should become part of the standard with C++0x.

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).

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

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.

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 for PCRE - Perl Compatible Regular Expression , I remembered using Mircosoft's GRETA as well.

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