Skip to content

coregex.MustCompile(^x(a|bc)).MatchString("xbc") // false #166

Closed

Description

@vmihailenco
  regexp.MustCompile(`^x(a|bc)`).MatchString("xbc")   // true
  coregex.MustCompile(`^x(a|bc)`).MatchString("xbc")  // false

Activity

  1. kolkov commented on Oct 8, 2026

    @kolkov
    Contributor

    @vmihailenco Thanks for the report, and apologies for the six-week silence — I somehow missed the notification and only caught this when reviewing the repo today. In parallel with coregex I've been developing a headless IDE (open-sourcing soon) for managing large Go codebases like GoGPU via MCP — think console GoLand with AI automation — along with daemon, fursy and relica.

    Confirmed and root-caused. ^x(a|bc) is the tip of two bugs in the anchored fast paths. Both produce wrong answers on common pattern shapes (routers, HTTP version checks, SemVer). The submatch path is not affected; Match, Find, FindAll, Count and ReplaceAll are.

    1. BranchDispatch ignores everything around the alternation. IsBranchDispatchPattern accepts any anchored concat that contains an alternation, but the dispatcher assumes the alternation starts at position 0 and ends the pattern:

    ^x(a|bc)              "xbc"        → false   (your report)
    ^HTTP/(1\.0|1\.1|2)   "HTTP/2"     → false
    ^/api/(users|posts)   "/api/users" → false
    ^(GET|POST) /         "GET x"      → true    (false positive: suffix ignored)
    ^(a\d|b)              "a"          → true    (false positive: non-literal branch "assumed true")
    

    2. First-byte extraction ignores FoldCase. regexp/syntax rewrites [Vv] as (?i:V); the extractor takes only the uppercase rune, so the fast-reject path discards lowercase input:

    ^[Vv]\d+   "v1" → false   ("V1" → true)
    

    Fix is in progress; I'll link the PR here and cut a patch release as soon as it lands. It will also add a cross-API invariant test for anchored patterns — MatchString(s) == (FindStringIndex(s) != nil) == (FindStringSubmatchIndex(s) != nil) — which is exactly the signal this class of bug produces.

  2. added
    type: bugSomething isn't working
    priority: criticalRelease blocker, correctness regression
    area: metaStrategy selection, engine orchestration
    area: nfaThompson NFA, PikeVM, BoundedBacktracker
    on Oct 8, 2026
  3. self-assigned this
    on Oct 9, 2026
  4. kolkov commented on Oct 9, 2026

    @kolkov
    Contributor

    Fixed in v0.12.27 — PR #172.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: metaStrategy selection, engine orchestrationarea: nfaThompson NFA, PikeVM, BoundedBacktrackerpriority: criticalRelease blocker, correctness regressiontype: bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions