Skip to content

[libc++] <regex>: \B should not be found in a+a #135009

Open
@Alcaro

Description

@Alcaro
#include <regex>
#include <stdio.h>

int main() {
    try {
        const char * s{"a+a"};
        std::regex r{"\\B"};
        std::cmatch m;
        bool result = std::regex_search(s, m, r);
        printf("regex_search: %d\n", result);
        for (unsigned i = 0; i < m.size(); ++i) {
            printf("m[%d]", i);
            if (m[i].matched) {
                printf(" = %d %d", (int)(m[i].first-s), (int)(m[i].second-s));
            } else {
                puts(".matched: false");
            }
        }
    } catch (const std::exception& e) {
        printf("Exception: %s\n", e.what());
    }
}

Expected: No match; all four positions in that string should be boundary.
Actual: libc++ thinks end of string is a non-boundary. It also returns match if searching for \b$.

https://godbolt.org/z/69q9ehe4v

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++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