Skip to content

strings: NewReplacer does not replace strings in order #25071

@nicksnyder

Description

@nicksnyder

What version of Go are you using (go version)?

go1.10.1

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

amd64
darwin

What did you do?

https://play.golang.org/p/oB5SCKv4LUx

r := strings.NewReplacer("aaa", "xxx", "bbbaaa", "yyy")
fmt.Println(r.Replace("bbbaaa")) // yyy

What did you expect to see?

I expected Replace to return bbbxxx.

The documentation says:

Replacements are performed in order, without overlapping matches.

I expect the aaa->xxx replacement to happen first so the second replacement bbbaaa->yyy shouldn't happen.

What did you see instead?

yyy

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions