mercredi 29 septembre 2021

Do regular expressions in the C++ library support lookahead?

I want to extract only the characters between '[' and ']' from the below string.
Only lookbehind ((?=\s\s\])) works, but lookahead ((?<=\[\s\s)) does not. The compiler throws exceptions.
Does c++ support lookahead? Or is there any way to retrieve the characters?

Thank you.

    string text = "Character[  r  ] = Frequency[ 1592 ]"
                  "Character[  ]  ] = Frequency[ 0 ]"
                  "Character[  T  ] = Frequency[ 76 ]"
                  "Character[  1  ] = Frequency[ 76 ]";

    regex pattern("(?<=\\[\\s\\s).(?=\\s\\s\\])");//  < ------

    bool bvalue = regex_search(text.begin(), text.end(), pattern);
    if (bvalue)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

Aucun commentaire:

Enregistrer un commentaire