12

Is there any full/correct implementation available (right now) for C++11 regex?

Note on Compiler support vs. Library support:

Compiler Support = compiler recognizes any new syntax added to the language for the feature in question. Code utilizing the new feature added to your program will compile.

Library Support = library updated to actually implement the feature. Code added to your program and linked to the library will work.

*Edit: I've updated this summary with new information and moved it into an answer below.

Drew Dormann
  • 59,987
  • 13
  • 123
  • 180
Arbalest
  • 1,095
  • 11
  • 23
  • 1
    There has been a lot of work recently to add `` support to libstdc++. At least part of the regex algorithms should be usable in GCC 4.9. – Morwenn Sep 03 '13 at 07:20
  • For MSVC you have msdn page with what syntax is supported by which version of visual http://msdn.microsoft.com/en-us/library/bb982727%28v=vs.120%29.aspx – ColdCat Sep 03 '13 at 07:53
  • Isn't Clang supposed to be C++11 fully compatible by now? [Clang status](http://clang.llvm.org/cxx_status.html) – RedX Sep 03 '13 at 11:35
  • 1
    @RedX Clang the compiler, yes. libc++ the library, also yes. In both cases, of course, there may be bugs. However, when you use Clang with a different standard library, you are of course limited to what that library supports, so if you use a current libstdc++, you don't have regex. – Sebastian Redl Sep 03 '13 at 11:45
  • there is "regex.h" that's super old and works for everything essentially. I was using but realized my build didn't C++11 so I essentially switched to "regex.h" (a little bit more complicated) and it worked. It's posix/windows also. – progrenhard Sep 05 '13 at 20:33

3 Answers3

13

Per stack exchange policy about it being ok to answer your own question I am updating the summary part of the question with new info and moving it into this answer.

GCC: Does not provide a working regex until GCC 4.9.0

Clang: Compiles regex

Standard Library:

  • regex only supported by libstdc++ since GCC 4.9.0 (GNU's standard lib)
  • regex is supported by libc++ (LLVM's standard lib)
  • libc++ fully verified on Mac OS
  • libc++ can be built from source for other platforms.
  • (I built and verified some of regex on Linux)

MSVC: Regex works since MSVC 2010 (Per answer from @Laurent and associated up votes)

Boost: C++11 regex is "based on" or "modeled after" Boost. I take that to mean not exactly the same. If there is a definitive list of differences please comment with a link.

Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521
Arbalest
  • 1,095
  • 11
  • 23
  • This list will be far more insightful than my answer, don't worry about answering your own question. +1 – Laurent Jalbert Simard Sep 05 '13 at 21:57
  • The GCC/Clang compiler part of this answer is irrelevant really, any version of GCC or Clang since about 2011 supports all the necessary language features for ``, it's only a question of whether it's provided in the standard library you use with the compiler. – Jonathan Wakely Apr 16 '15 at 16:28
5

I've used the <regex> module since MSVC 2010 and it worked perfectly for my need (using the doc from cplusplus.com).

So if you intend to develop on a Windows environment, I would recommend opting for MSVC 2010 or 2012. It works out of the box !

Laurent Jalbert Simard
  • 5,949
  • 1
  • 28
  • 36
1

Clang is C++11 feature complete. You can check which feature is available in which version here: Clang C++11 features

RedX
  • 14,749
  • 1
  • 53
  • 76