2012-10-16 4 views
4

가능한 중복 :
Is gcc4.7 buggy about regular expressions?C++ 11 표준 : regex_match 돌아 여분의 문자

내가 http://www.cplusplus.com/reference/std/regex/regex_match/의 예를 다음과 우분투 12.04에 컴파일 된 64 비트 g와 ++ 버전 4.6 .3

내 출력은 다음과 같습니다.

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] 

샘플 출력하지만 내 머신 [bject]이 옳지 않다 추출하는 것을

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] 

통지. 어떤 아이디어?

+0

참으로 ... http://liveworkspace.org/code/05747d2336f0fcd071aba84ba3fd13fb –

+0

그것은 std : regex의 버그라는 것을 의미합니까? – Jeremy

+0

이 결과 (동일한 환경)를 확인할 수 있습니다. –

답변

0

당신은에 예를 줄일 수

std::string s("subject"); 
std::regex e("(sub)(.*)"); 
std::smatch sm; 
std::regex_match(s, sm, e); 

더욱 흥미로운 :

std::string s("subject"); 
std::regex e("(sub)(ject)"); 
std::smatch sm; 
std::regex_match(s, sm, e); 

그래서, 이것은 GNU 구현의 버그처럼 보인다.

+0

아직 완벽하게 구현되지 않았습니다. – moooeeeep

+0

@moooeeeep 올바르게 작성하십시오 ;-) –

+0

불완전하다는 것은 잘못된 것을 의미합니다. – moooeeeep

3

gcc implementation status (ver 4.6.3)에 따르면 정규 표현식 라이브러리는 아직 완전히 구현되지 않았습니다. 오류가 발생하지 않으며 경고가 표시되지 않습니다. 실제로 불쾌하다.

그러나, 다른 사람은 물론 최신 버전으로, 이전이 관찰 :

일반적인 제안은 더하다을 사용하십시오.3210 또는 다른 컴파일러로 시도하십시오.

자세한 내용은 this answer을 참조하십시오.

관련 문제