Skip to content

str replace should use plain string by default #8037

@kubouch

Description

@kubouch

Describe the bug

Currently, str replace uses regex by default which might be surprising, e.g., on Windows in cases like 'C:\Users\kubouch' | str replace 'C:\Users' 'foo'.

How to reproduce

> 'C:\Users\kubouch' | str replace 'C:\Users' 'foo'
Error: nu::shell::unsupported_input (link)

  × Unsupported input
   ╭─[entry #4:1:1]
 1 │ 'C:\Users\kubouch' | str replace 'C:\Users' 'foo'
   ·                      ─────┬───── ─────┬────
   ·                           │           ╰── input type: value originates from here
   ·                           ╰── Parsing error at position 4: Invalid hex escape
   ╰────

Expected behavior

foo\kubouch

The solution is to use the --string flag but I think it should be the other way: String by default and regex with --regex flag

Screenshots

No response

Configuration

key value
version 0.75.1
branch main
commit_hash f4bd78b
build_os windows-x86_64
build_target x86_64-pc-windows-msvc
rust_version rustc 1.66.1 (90743e729 2023-01-10)
rust_channel 1.66.1-x86_64-pc-windows-msvc
cargo_version cargo 1.66.1 (ad779e08b 2023-01-10)
pkg_version 0.75.1
build_time 2023-02-11 12:40:58 +02:00
build_rust_channel release
features database, dataframe, default, trash, which, zip
installed_plugins

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    polishthis problem makes nu feel unpolishedsemanticsPlaces where we should define/clarify nushell's semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions