regex - Easy-to-Use Regular Expression Support in C++?


Translate

I'm looking for a robust, easy-to-use, regular expression evaluator for native C++, either platform-independent or Windows-specific.

Requirements:

  • Can't use Boost or ACE regex libraries (unfortunately)
  • Can't use .NET Regex (or any managed code)

The main requirement is that it should be standalone and open.


Toutes les réponses
  • Translate

    C++11 now includes the support of regular expressions. It will be platform independent. You just need a recent compiler. Check the following list to know which one to use.

    http://wiki.apache.org/stdcxx/C%2B%2B0xCompilerSupport

    Hope it helps


  • Translate

    try libpcre

    If you're stuck on windows they have a windows port which should work. I know e-texteditor uses it, so at least that's proof it works :-)


  • Translate

    If you use Visual Studio you can use Visual C++ 2008 Feature Pack Release, this implements some of TR1, and includes regular expression parsing. Get it


  • Translate

    Qt has also a nice Regular Expression implementation QRegExp. It is also platform independent.


  • Translate

    The GNU C Library supports regular expressions. It's open, and the RE code seems to be easily extractable.


  • Sandy Lee
    Translate

    The GNU C library regular expressions facility (regcomp(), regexec() and friends) is broken. Use libetre instead; the function signatures match the ones provided by glibc. http://laurikari.net/tre/


  • Translate

    I would second the recommendation for PCRE. I have used it in C++ projects in Windows and it works great. It's free, even for building commercial software. It also implements something of a de facto standard regular expression language, which will be welcome to your users. PCRE is of course Perl-compatible, and Python also uses the same library.

    The native PCRE interface is a bit awkward and very C-style, so it's probably worth writing a nice C++ wrapper around it. There is very likely already is one out there, but I'm not familiar with any.


  • Translate

    C++11 and forward now contains the standard regular expression library.
    Include the <regex> header, and use.


  • Translate

    Why don't you use Microsoft ATL's regex library? Kenny Kerr has written a short article on that recently.

    ATL includes a lightweight regular expression implementation. Although originally part of Visual C++, it is now included with the ATL Server download.

    The CAtlRegExp class template implements the parser and matching engine. ...

    The regular expression grammar is defined at the top of the atlrx.h header file.


  • Translate

    The free ATL Server Library and Tools from CodePlex includes a regex parser. See AtlServer in the CodePlex Archive

    ATL Server is a library of C++ classes that allow developers to build both client and server parts of service-type C++ applications and web services. It provides much of the functionality required to build large scale internet sites, such as SOAP messaging, caching facilities, threading facilities, regular expression processing, management of session-state, performance monitoring, MIME support, integration with IIS and class for interacting with security and cryptographic infrastructure. The earlier versions of the library are parts of Visual Studio 2002, Visual Studio 2003 and Visual Studio 2005. The project has started from the version of the library released as part of Visual Studio 2005 SP1.