Skip to content

<regex>: Fix word bounds \b and \B when applied to the empty string - #5375

Merged
Stephan T. Lavavej (StephanTLavavej) merged 3 commits into
microsoft:mainfrom
muellerj2:regex-fix-word-bounds-on-empty-string
Apr 10, 2025
Merged

<regex>: Fix word bounds \b and \B when applied to the empty string#5375
Stephan T. Lavavej (StephanTLavavej) merged 3 commits into
microsoft:mainfrom
muellerj2:regex-fix-word-bounds-on-empty-string

Conversation

@muellerj2

Copy link
Copy Markdown

Fixes #5371.

The ECMAScript standard effectively states that \b matches a position i in the string iff IsWordChar(i-1) xor IsWordChar(i) is true. It also defines that for positions i = -1 and i = length(input), IsWordChar(i) always returns false. Thus, \b does not match anything in the empty string.

Since \b does not match the empty string, the flags match_not_bow and match_not_eow don't matter in this case.

@muellerj2
Julian Müller (muellerj2) requested a review from a team as a code owner March 28, 2025 17:31
@github-project-automation github-project-automation Bot moved this to Initial Review in STL Code Reviews Mar 28, 2025
@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) added bug Something isn't working regex meow is a substring of homeowner labels Mar 29, 2025
Comment thread tests/std/tests/VSO_0000000_regex_use/test.cpp Outdated
@StephanTLavavej

Copy link
Copy Markdown
Member

Thanks for the fix, test coverage, and clear writeup with citations! I pushed a trivial change to use raw string literals.

@StephanTLavavej

Copy link
Copy Markdown
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej

Copy link
Copy Markdown
Member

Resolved adjacent-add conflict in VSO_0000000_regex_use.

@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit b69d5f5 into microsoft:main Apr 10, 2025
@github-project-automation github-project-automation Bot moved this from Merging to Done in STL Code Reviews Apr 10, 2025
@StephanTLavavej

Copy link
Copy Markdown
Member

🐝 🪲 🐞

@muellerj2
Julian Müller (muellerj2) deleted the regex-fix-word-bounds-on-empty-string branch April 13, 2025 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working regex meow is a substring of homeowner

3 participants