在C ++ 11中使用regex lookbehinds [英] Using regex lookbehinds in C++11

查看:113
本文介绍了在C ++ 11中使用regex lookbehinds的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我不能在C ++ 11中使用lookbehinds? Lookahead工作正常。

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

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

这将引发以下异常:

The expression contained mismatched ( and ).

这不会引发任何异常:

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

我缺少什么?

推荐答案

C ++ 11 < regex> 使用ECMAScript(ECMA-262)regex语法,因此不会有look-behind(C ++ 11支持的其他正则表达式也没有后备)。

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 doesn't have look-behind).

如果你的用例需要使用look -behind,您可以考虑改用 Boost.Regex

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

这篇关于在C ++ 11中使用regex lookbehinds的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆