match返回额外字符

match返回额外字符

本文介绍了C ++ 11 std :: regex_match返回额外字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照并在Ubuntu 12.04 64位上使用g ++ 4.6.3版编译



以下是我的输出:



匹配的字符串
匹配的字符串对象
匹配的范围
包含3个匹配的字符串字符串
string对象有3个匹配
范围与3个匹配
匹配项是:[subject] [sub] [bject]

虽然示例输出是:

 字符串文字匹配
string对象匹配
范围匹配
字符串文字与3个匹配
string对象与3个匹配
范围与3个匹配
匹配项是:[subject] [sub] [object]

请注意,在我的机器 [bject] 任何想法?

解决方案

根据 regex库还没有完全实现。它不抛出错误,不提供警告。



但是,其他人已经观察过这种情况,还有更新的版本:










常见的建议是进一步使用或以尝试其他编译器。



请参阅以便进一步阅读。


I followed the example on http://www.cplusplus.com/reference/std/regex/regex_match/ and compiled on Ubuntu 12.04 64-bit with g++ version 4.6.3

The following is my output:

string literal matched
string object matched
range matched
string literal with 3 matches
string object with 3 matches
range with 3 matches
the matches were: [subject] [sub] [bject]

While the sample output is:

string literal matched
string object matched
range matched
string literal with 3 matches
string object with 3 matches
range with 3 matches
the matches were: [subject] [sub] [ject]

Notice that on my machine [bject] is extracted which is not right. Any ideas?

解决方案

According to the gcc implementation status (ver 4.6.3) the regex library is not yet completely implemented. It throws no errors and provides no warnings. Which is unpleasant, indeed.

However, others have observed this before, with more recent versions as well:

The common suggestion is to further use Boost.Regex or to give a try to another compiler.

See this answer for some further reading.

这篇关于C ++ 11 std :: regex_match返回额外字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 07:13