Home Dashboard Directory Help
Search

std::regex bug in vs2010 by prog76


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 641845
Opened: 2/7/2011 9:45:52 PM
Access Restriction: Public
2
Workaround(s)
view
1
User(s) can reproduce this bug

Description

When matching with std::regex results is wrong. Group 4 should not be empty.

^\s*(\d\d\d)T\s+'(.*)'\s*(?:\((\d+)\))?\s*(?:\(\s*(.*?)\s*\))?.*
against
123T 'DATA'(THE)
Details
Sign in to post a comment.
Posted by Microsoft on 2/8/2011 at 6:52 PM
Hi,

Thanks for reporting this bug. We've already fixed it, and the fix will be available in VC11. Here's a slightly modified test case with the same string and regex:

C:\Temp>type meow.cpp
#include <stddef.h>
#include <iostream>
#include <ostream>
#include <regex>
#include <string>
using namespace std;

int main() {
    cout << "_MSC_FULL_VER: " << _MSC_FULL_VER << endl;

    const string s(" 123T 'Data'(THE)");
    const string reg("^\\s*(\\d\\d\\d)T\\s+'(.*)'\\s*(?:\\((\\d+)\\))?\\s*(?:\\(\\s*(.*?)\\s*\\))?.*");
    const regex r(reg);

    cout << " s: \"" << s << "\"" << endl;
    cout << " r: \"" << reg << "\"" << endl;

    smatch m;

    if (regex_search(s, m, r)) {
        for (size_t i = 0; i < m.size(); ++i) {
            cout << "m[" << i << "]: \"" << m[i] << "\"" << endl;
        }
    } else {
        cout << "FALSE" << endl;
    }
}

[VC10 RTM]
C:\Temp>cl /EHsc /nologo /W4 meow.cpp
meow.cpp

C:\Temp>meow
_MSC_FULL_VER: 160030319
s: " 123T 'Data'(THE)"
r: "^\s*(\d\d\d)T\s+'(.*)'\s*(?:\((\d+)\))?\s*(?:\(\s*(.*?)\s*\))?.*"
m[0]: " 123T 'Data'(THE)"
m[1]: "123"
m[2]: "Data"
m[3]: ""
m[4]: ""

[My current build of VC11]
C:\Temp>cl /EHsc /nologo /W4 meow.cpp
meow.cpp

C:\Temp>meow
_MSC_FULL_VER: 170040203
s: " 123T 'Data'(THE)"
r: "^\s*(\d\d\d)T\s+'(.*)'\s*(?:\((\d+)\))?\s*(?:\(\s*(.*?)\s*\))?.*"
m[0]: " 123T 'Data'(THE)"
m[1]: "123"
m[2]: "Data"
m[3]: ""
m[4]: "THE"

If you have any further questions, feel free to E-mail me at stl@microsoft.com .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by Microsoft on 2/7/2011 at 9:58 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by prog76 on 2/9/2011 at 8:30 PM
Thanks.
Posted by Viorel_ on 2/8/2011 at 12:03 AM
Try without the endmost '.*':

#define PATTERN "^" "\\s*" "(\\d\\d\\d)T\\s+'(.*)'\\s*(?:\\((\\d+)\\))?\\s*(?:\\(\\s*(.*?)\\s*\\))?"