Skip to content

<regex>: \b and \B are backwards on empty strings #5371

@Alcaro

Description

@Alcaro

Describe the bug

\b and \B are backwards on empty strings

Command-line test case

https://godbolt.org/z/9TnqKsvbe

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

int main() {
    try {
        std::string s{""};
        std::regex r{"\\b"};
        std::smatch 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(".str(): \"%s\"\n", m[i].str().c_str());
            } else {
                puts(".matched: false");
            }
        }
    } catch (const std::exception& e) {
        printf("Exception: %s\n", e.what());
    }
}

Expected behavior

Same as libstdc++, libc++ and Firefox: \B should match empty string, \b should not

STL version

Whatever's on Godbolt (I couldn't check if it's fixed on latest, but I did check for duplicate issues/PRs and found nothing)

Additional context

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!regexmeow is a substring of homeowner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions