Skip to content

Is the regex [b-a] legal? #110339

@Alcaro

Description

@Alcaro
#include <regex>

int main()
{
    try {
        std::regex r("[\\d-e]");
        puts("it's legal");
    } catch (std::exception& e) {
        puts(e.what());
    }
    try {
        std::regex r("[b-a]");
        puts("it's legal");
    } catch (std::exception& e) {
        puts(e.what());
    }
}

https://godbolt.org/z/oMvEr5YTs

Output: The expression contained an invalid character range, such as [b-a] in most encodings. and it's legal

Expected behavior: I'd expect that if I can produce an error saying that [b-a] is invalid, then an input of [b-a] returns that same error.

(Also, if you change it to [1-0], it's illegal in all encodings. The C and C++ specs demand that 0-9 are ascending and consecutive.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateResolved as duplicatelibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.regexIssues related to regex

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions