Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using regex lookbehinds in C++11

Tags:

c++

regex

c++11

Why can't I use lookbehinds in C++11? Lookahead works fine.

std::regex e("(?<=a)b");

This will throw the following exception:

The expression contained mismatched ( and ).

This wont throw any exception:

std::regex e("a(?=b)");

What am I missing?

like image 301
Carlj901 Avatar asked Jan 26 '13 16:01

Carlj901


1 Answers

C++11 <regex> uses ECMAScript's (ECMA-262) regex syntax, so it will not have look-behind (other flavors of regex that C++11 supports also don't have look-behind).

If your use case requires the use of look-behind, you may consider using Boost.Regex instead.

like image 93
nhahtdh Avatar answered Oct 08 '22 01:10

nhahtdh