C ++ stdex :: wregex проблема с \ S \ s - PullRequest
0 голосов
/ 12 июня 2019

Я пытался проанализировать некоторые строки, используя std :: wregex, и обнаружил, что когда я использую [\ S \ s] +, он не может обработать символ Unicode EN-DASH (8211).

Кто-нибудь знает, есть ли причина, по которой EN-DASH не рассматривается ни как пробел, ни как пробел, или я делаю что-то не так?

void test (const std::wstring& testDesc, const std::wstring& expresion, const std::wstring& text)
{
    std::wcout << L"Test   : " << testDesc << std::endl;
    std::wcout << L"Regex  : " << expresion << std::endl;
    std::wregex regex (expresion);
    std::wstring regExParams (text);
    if (std::regex_search (regExParams, regex))
    {
        std::wcout << L"Result : Matched" << std::endl;
    }
    else
    {
        std::wcout << L"Result : No match" << std::endl;
    }
    std::wcout << std::endl;
}

int main ()
{
    const std::wstring text1 = L"¬Line1\nLine2¬Line3\nLine4¬Line–5¬";       // 3rd char from the end is the EN-DASH
    const std::wstring text2 = L"¬Line1\nLine2¬Line3\nLine4¬Line-5¬";       // 3rd char from the end if a hyphen
    const std::wstring expresion1 = L"^¬[\\S\\s]+¬[\\S\\s]+¬[\\S\\s]+¬$";   // This pattern will fail on EN-DASH
    const std::wstring expresion2 = L"^¬[^¬]+¬[^¬]+¬[^¬]+¬$";               // This pattern will succeeds with EN-DASH
    test (L"Test 1", expresion1, text1);    // Fail
    test (L"Test 2", expresion2, text1);    // Pass
    test (L"Test 3", expresion1, text2);    // Pass
    test (L"Test 4", expresion2, text2);    // Pass
    return 1;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...