C ++中易于使用的正则表达式支持吗?

时间:2020-03-05 18:37:29  来源:igfitidea点击:

我正在寻找一个针对本机C ++的健壮,易于使用的正则表达式评估器,该评估器可独立于平台或者特定于Windows。

要求:

  • 不能使用Boost或者ACE正则表达式库(不幸的是)
  • 不能使用.NET正则表达式(或者任何托管代码)

主要要求是它应该独立且开放。

解决方案

回答

尝试libpcre

如果我们被困在Windows上,它们有一个可以正常工作的Windows端口。我知道电子文本编辑器会使用它,因此至少可以证明它有效:-)

回答

GNU C库支持正则表达式。它是开放的,并且RE代码似乎很容易提取。

回答

GNU C库正则表达式工具(regcomp(),regexec()和friends)已损坏。改用libetre;函数签名与glibc提供的签名匹配。
http://laurikari.net/tre/

回答

如果使用Visual Studio,则可以使用Visual C ++ 2008 Feature Pack Release,它实现了某些TR1,并包括正则表达式解析。得到它

回答

Qt还有一个很好的正则表达式实现QRegExp。它也是平台无关的。

回答

我们为什么不使用Microsoft ATL的正则表达式库?肯尼·科尔(Kenny Kerr)最近写了一篇简短的文章。

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.

回答

我赞成PCRE的建议。我已经在Windows的C ++项目中使用了它,并且效果很好。它是免费的,甚至用于构建商业软件。它还实现了事实上的标准正则表达式语言,将欢迎用户。 PCRE当然是Perl兼容的,Python也使用相同的库。

本机PCRE接口有点笨拙,非常具有C风格,因此可能值得为它编写一个不错的C ++包装器。很可能已经有一个了,但是我不熟悉任何一个。

回答

CodePlex的免费ATL Server库和工具包括一个正则表达式解析器。请参阅CodePlex存档中的AtlServer

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.