Skip to content

with -p: a regex literal's .replace replaces only the first match per line — sed s/a/b/g parity is broken #1607

Closed

Description

@ehartford

CLAUDE.md promises sed 's/old/new/g' → ... | with -p 'line = line.replace("old", "new")' and sed -E 's/(a)(b)/\2\1/' → /(a)(b)/.replace(line, "$2$1"). The regex form replaces the first match only:

$ echo "it it it" | with -p 'line = /\bit\b/.replace(line, "x")'
x it it

Expected x x x — a per-line transform is the g case by default (there is no non-g sed idiom worth a spelling). Found by the stage 9 agent migrating fixtures (it had to loop). docs/improve_oneliners.md parity matrix should mark the row until fixed. Compiler: installed with v0.15.2.1 (main d783366).

Activity

  1. added
    bug
    on Sep 24, 2026
  2. ehartford commented on Sep 26, 2026

    @ehartford
    ContributorAuthor

    Working as specified. docs/completed/regex-spec.md defines the g flag as "Global — find all matches (affects =~ and replace)", and lib/std/regex.w implements it: echo 'it it it' | with -p 'line = /\bit\b/g.replace(line, "x")' prints x x x; without g the first match only, as in sed. The one-liner table now shows the /g spelling (commit on the ruled-fixes stack layer).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions