20

Could someone explain the differences between the two? Which would be better to learn right now? How would knowledge transfer from one to the other and vice-versa?

2
  • 6
    Learning the standard way is never a bad thing. Commented Sep 28, 2011 at 21:37
  • 4
    Be careful with the Standard Library C++11 Regex, because it is still not fully implemented by GCC: stackoverflow.com/questions/4716680/c0x-regex-in-gcc Commented Aug 1, 2012 at 22:26

3 Answers 3

11

The boost regex library made it into C++0x so I'm guessing it will slowly be removed from boost. However, using boost is nice because you can still use it with compilers without C++0x support. So it's really up to you.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, but can one migrate a Boost.Regex-based program to C++11 Regex with a simple s/boost::/std::/g ?
@Rob : I imagine that depends on whether you're using Boost.Regex's ICU support.
@Robᵩ There are some minor changes that make the two implementations not a drop-in replacement for the other. e.g. stackoverflow.com/questions/37829849/…
8

One major difference is, that C++11 does not provide the Perl syntax for regular expressions. So, if you tend to use Perl syntax you have to use the Boost::Regex library.

9 Comments

Yes there is Perl syntax for regex : There is ECMAScript regex and ECMAScript regex is the same as Perl regex ecma-international.org/ecma-262/5.1/#sec-15.10
@Ubiquité you are not correct. The link you provided says "modeled after". The C++ TR1 proposal for <regex> uses the very similar phrasing "based on". ECMAScript regular expressions are not the same thing as Perl regular expressions -- Perl provides more features and some different syntax.
@PatrickNiedzielski: You are correct, unfortunately Boost.Regex defined perl as equivalent to ECMAScript boost.org/doc/libs/1_53_0/libs/regex/doc/html/boost_regex/ref/….
@kennytm does that mean boost "perl" regex syntax and C++11 ECMAScript regex are the same?
@MahmoudAl-Qudsi. Yes. However, as of 1.64.0, boost's "ECMAScript" regex actually implements a lot of Perl-but-not-ECMAScript regex features.
|
1

At least in Visual Studio 2013 this and related names (cmatch, regex_match) are the same in both namespaces. They also have the same (or similar?) interface.

So you can just change namespace and the same code will be compiled with another regex without warning and errors. And it should work the same of course.

P.S. I would prefer std::regex since it is part of C++11 and boost::regex is a third-party library. I'm sure few years later, boost will remove support for boost::regex.

2 Comments

There are some minor chages that make the two implementations not a drop-in replacement for the other. e.g. stackoverflow.com/questions/37829849/…
And I would not expect removing regex from boost even if they were drop-in replacements for each other. Those expectation was too adventurous.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.