19

Does it? If yes, where can I get the documentation for it... if not, then which would be the best alternative?

aviraldg
  • 9,531
  • 6
  • 41
  • 56

9 Answers9

31

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.

Community
  • 1
  • 1
Joris Timmermans
  • 10,814
  • 2
  • 49
  • 75
  • This answer is dated, as of 2012 the answer is now Yes, C++ has a standard regex library, mandated by C++11, under the header "regex" – Anne Quinn Aug 03 '12 at 01:39
  • @Clairvoire - I've decided to edit / update my answer to the changes since late 2009, thanks for the heads-up on this outdated answer. – Joris Timmermans Aug 03 '12 at 07:13
  • The difference is also the c++ standard does not support named subgroups, that is naming parts of regular expressions so that later you can get them by name. – user3111311 Jan 23 '14 at 12:57
8

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

che
  • 12,097
  • 7
  • 42
  • 71
6

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

5

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

Paolo Tedesco
  • 55,237
  • 33
  • 144
  • 193
3

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

Michael Krelin - hacker
  • 138,757
  • 24
  • 193
  • 173
2

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

RED SOFT ADAIR
  • 12,032
  • 10
  • 54
  • 92
1

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.

larsmoa
  • 12,604
  • 8
  • 62
  • 85
1

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.

jochenleidner
  • 83
  • 1
  • 5
0

+1 for PCRE - Perl Compatible Regular Expression , I remembered using Mircosoft's GRETA as well.

ukanth
  • 2,718
  • 5
  • 28
  • 38