Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<regex>: c++ regex character class case insensitive search problem #993

Closed
AlexGuteniev opened this issue Jul 5, 2020 · 0 comments · Fixed by #1503
Closed

<regex>: c++ regex character class case insensitive search problem #993

AlexGuteniev opened this issue Jul 5, 2020 · 0 comments · Fixed by #1503
Labels
bug Something isn't working fixed Something works now, yay!

Comments

@AlexGuteniev
Copy link
Contributor

AlexGuteniev commented Jul 5, 2020

Describe the bug
regex::icase is not handled correctly for some input.

Command-line test case

d:\Temp2>type repro.cpp
#include <iostream>
#include <regex>

using namespace std;

int main()
{
        wstring target(L" Copyright");
        wsmatch match;
        wregex regexp(L"[a-z][a-z]", regex::icase);
        if (regex_search(target.cbegin(), target.cend(), match, regexp)) {
                wcout << L"Matched: \"" << match.str() << L"\"" << endl;
        }
        return (0);
}
d:\Temp2>cl /EHsc /W4 /WX .\repro.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.27.29009.1 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

repro.cpp
Microsoft (R) Incremental Linker Version 14.27.29009.1
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:repro.exe
repro.obj

d:\Temp2>.\repro.exe
Matched: "op"

Expected behavior

Matched: "Co"

Command-line test case 2

d:\Temp2>type repro.cpp
#include <regex>
#include <iostream>

int main()
{
        const wchar_t* test_raw_string = L"blahZblah";
        const wchar_t* test_patterns[] = { L"[Z]", L"[z]" };

        for (const auto* test_pattern : test_patterns)
        {
                const std::wstring test_string = test_raw_string;
                std::wregex case_regex(test_pattern, std::regex_constants::ECMAScript);
                std::wcmatch match1;

                std::wcout << test_pattern << L" search " << test_string << L" case sensitive = " << std::regex_search(test_string, case_regex) << L'\n';
                std::wcout << test_pattern << L" search " << test_string << L" case sensitive with match = " << std::regex_search(test_raw_string, match1, case_regex) << L'\n';

                std::wregex icase_regex(test_pattern, std::regex_constants::icase | std::regex_constants::ECMAScript);
                std::wcmatch match2;

                std::wcout << test_pattern << L" search " << test_string << L" case insensitive = " << std::regex_search(test_string, icase_regex) << L'\n';
                std::wcout << test_pattern << L" search " << test_string << L" case insensitive with match = " << std::regex_search(test_raw_string, match2, icase_regex) << L'\n';

                std::wcout << L'\n';
        }
    return 0;
}


d:\Temp2>cl /EHsc /W4 /WX .\repro.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.27.29009.1 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

repro.cpp
Microsoft (R) Incremental Linker Version 14.27.29009.1
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:repro.exe
repro.obj

d:\Temp2>.\repro.exe
[Z] search blahZblah case sensitive = 1
[Z] search blahZblah case sensitive with match = 1
[Z] search blahZblah case insensitive = 0
[Z] search blahZblah case insensitive with match = 0

[z] search blahZblah case sensitive = 0
[z] search blahZblah case sensitive with match = 0
[z] search blahZblah case insensitive = 0
[z] search blahZblah case insensitive with match = 0

Expected behavior 2

[Z] search blahZblah case sensitive = 1
[Z] search blahZblah case sensitive with match = 1
[Z] search blahZblah case insensitive = 1
[Z] search blahZblah case insensitive with match = 1

[z] search blahZblah case sensitive = 0
[z] search blahZblah case sensitive with match = 0
[z] search blahZblah case insensitive = 1
[z] search blahZblah case insensitive with match = 1

STL version

Microsoft Visual Studio Professional 2019 Preview
Version 16.7.0 Preview 3.1

Additional context
This item is also tracked on Developer Community as DevCom-230267 and DevCom-246258 and by Microsoft-internal VSO-287844 / AB#287844.

See also #405

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Something works now, yay!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants