std :: regex是否支持“(?i)”?不区分大小写? [英] Does std::regex support "(?i)" for case insensitivity?

查看:224
本文介绍了std :: regex是否支持“(?i)”?不区分大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio2010。这...

I am using Visual Studio 2010. This...

std :: regex pattern((?i)。* a。 *);

...将其抛出...

...throws this...

std :: tr1 :: regex_error-正则表达式错误

...,我找不到任何提示是否 std :: regex 支持(?i)语法是否区分大小写。

...and I can't find anything that says if std::regex supports the (?i) syntax for case insensitivity or not.

任何人都可以确认/否认 std不支持(?i)作为不区分大小写的前缀: :regex

Can anyone confirm/deny that (?i) is not supported as a prefix for case insensitivity by std::regex?

推荐答案

该标准仅要求符合POSIX正则表达式语法(不要求包括像这样的Perl扩展名)并符合ECMAScript正则表达式规范(除少数例外,根据ISO14882-2011§28.13),这在ECMA-262,§15.10.2中进行了描述。 ECMAScript的正则表达式语法不包括使用(?)语法形式的修饰符,因此,通过扩展,C +也不+ 11/14,TR1的大多数实现也不是。

The standard only requires conformance to the POSIX regular expression syntax (which does not include Perl extensions like this one) and conformance to the ECMAScript regular expression specification (with minor exceptions, per ISO 14882-2011§28.13), which is described in ECMA-262, §15.10.2. ECMAScript's regular expression grammar does not include the use of modifiers in the form of the (?) syntax, so, by extension, neither does C++11/14, nor do most implementations of TR1.

这并不妨碍您的标准库实现更多的PCRE扩展,但是该标准不需要它,因此它是

That does not preclude your standard library from implementing more PCRE extensions, but the standard does not require it, so it's simply not guaranteed.

因此,不,它本身不受支持。

So, no, it's not supported, per se.

但是,您可以声明正则表达式,如下所示:

You can, however declare your regular expression as follows:

std::regex pattern(".*a.*", std::regex_constants::icase);

这将声明您的模式不区分大小写。

This will declare your pattern to be case-insensitive.

这篇关于std :: regex是否支持“(?i)”?不区分大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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