Boost.Regex vs C++11 Regex
Asked Answered
M

3

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?

Michail answered 28/9, 2011 at 21:13 Comment(2)
Learning the standard way is never a bad thing.Abrade
Be careful with the Standard Library C++11 Regex, because it is still not fully implemented by GCC: https://mcmap.net/q/197234/-c-0x-regex-in-gccChristianize
C
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.

Cowpoke answered 28/9, 2011 at 21:20 Comment(3)
Yes, but can one migrate a Boost.Regex-based program to C++11 Regex with a simple s/boost::/std::/g ?Marcellamarcelle
@Rob : I imagine that depends on whether you're using Boost.Regex's ICU support.Rhizopod
@Robᵩ There are some minor changes that make the two implementations not a drop-in replacement for the other. e.g. #37830349Verla
M
7

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.

Marela answered 1/8, 2012 at 21:36 Comment(9)
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.10Heliport
@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.Agrology
@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/….Jeanett
@Jeanett does that mean boost "perl" regex syntax and C++11 ECMAScript regex are the same?Nighthawk
@MahmoudAl-Qudsi. Yes. However, as of 1.64.0, boost's "ECMAScript" regex actually implements a lot of Perl-but-not-ECMAScript regex features.Jeanett
@Jeanett But std::regex doesn't? Or does too?Bole
@FelixDombek std::regex does not.Jeanett
@Jeanett if you read the bottom of that boost doc, it says: "The options normal, ECMAScript, JavaScript and JScript are all synonyms for perl."Stonyhearted
@Stonyhearted that just means that they don't distinguish the flavours in their implementation (you get everything enabled always)Springs
A
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.

Allegedly answered 10/1, 2015 at 23:40 Comment(2)
There are some minor chages that make the two implementations not a drop-in replacement for the other. e.g. #37830349Verla
And I would not expect removing regex from boost even if they were drop-in replacements for each other. Those expectation was too adventurous.Allegedly

© 2022 - 2024 — McMap. All rights reserved.