From 2979595cc5223ce98d106893cccd55982895d5b5 Mon Sep 17 00:00:00 2001 From: "Tristan P." <65556393+quadristan@users.noreply.github.com> Date: Wed, 9 Oct 2024 20:35:56 +0200 Subject: [PATCH] [str replace] add exemple for escaped regexes (#14038) # Description This is a follow-up of https://github.com/nushell/nushell.github.io/pull/1584 The goal is to provide the user understanding of how to escape strings # User-Facing Changes Nothing except documentation # Tests + Formatting I don't know why but these two tests are failing on my system: - `test_std_util path_add` - `commands::umkdir::mkdir_umask_permission` Since I hardly believe it is linked to my changes, I will let your CI check it. Meanwhile, I will check my system, highly likely that it is something something related to me recently switching shells, hacking my way through prompts environments, etc. # After Submitting Will check how to re-generate the [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged --- crates/nu-command/src/strings/str_/replace.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/nu-command/src/strings/str_/replace.rs b/crates/nu-command/src/strings/str_/replace.rs index c15d0003aa..a893a88c62 100644 --- a/crates/nu-command/src/strings/str_/replace.rs +++ b/crates/nu-command/src/strings/str_/replace.rs @@ -156,12 +156,17 @@ impl Command for SubCommand { result: Some(Value::test_string("my_library.nu")), }, Example { - description: "Find and replace all occurrences of find string using regular expression", + description: "Find and replace contents with capture group using regular expression, with escapes", + example: "'hello=world' | str replace -r '\\$?(?.*)=(?.*)' '$$$varname = $value'", + result: Some(Value::test_string("$hello = world")), + }, + Example { + description: "Find and replace all occurrences of found string using regular expression", example: "'abc abc abc' | str replace --all --regex 'b' 'z'", result: Some(Value::test_string("azc azc azc")), }, Example { - description: "Find and replace all occurrences of find string in table using regular expression", + description: "Find and replace all occurrences of found string in table using regular expression", example: "[[ColA ColB ColC]; [abc abc ads]] | str replace --all --regex 'b' 'z' ColA ColC", result: Some(Value::test_list ( @@ -173,7 +178,7 @@ impl Command for SubCommand { )), }, Example { - description: "Find and replace all occurrences of find string in record using regular expression", + description: "Find and replace all occurrences of found string in record using regular expression", example: "{ KeyA: abc, KeyB: abc, KeyC: ads } | str replace --all --regex 'b' 'z' KeyA KeyC", result: Some(Value::test_record(record! {