mirror of
https://github.com/nushell/nushell
synced 2024-11-10 15:14:14 +00:00
add a "capture" example to str replace
, before the fancy ones (#9447)
closes https://github.com/nushell/nushell/issues/9437 cc/ @Sygmei 😉 # Description the syntax of *captures* used in `str replace` can be confusing for people not used to the `regex` syntax. there is already a capture example in `help str replace` ```bash Find and replace with fancy-regex > 'a successful b' | str replace '\b([sS])uc(?:cs|s?)e(ed(?:ed|ing|s?)|ss(?:es|ful(?:ly)?|i(?:ons?|ve(?:ly)?)|ors?)?)\b' '${1}ucce$2' a successful b ``` but it's really not trivial to understand the *capture* syntax... this PR adds a simpler example only focused on *captures* 🥳 ```bash Use captures to manipulate the input text > "abc-def" | str replace "(.+)-(.+)" "${2}_${1}" def_abc ``` # User-Facing Changes an example in `help str replace` to understand the syntax of *captures*. # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - ⚫ `toolkit test` - ⚫ `toolkit test stdlib` # After Submitting ``` $nothing ```
This commit is contained in:
parent
67b1dcae44
commit
bb30051006
1 changed files with 5 additions and 0 deletions
|
@ -133,6 +133,11 @@ impl Command for SubCommand {
|
||||||
example: r#"'abc abc abc' | str replace -a 'b' 'z' -s"#,
|
example: r#"'abc abc abc' | str replace -a 'b' 'z' -s"#,
|
||||||
result: Some(Value::test_string("azc azc azc")),
|
result: Some(Value::test_string("azc azc azc")),
|
||||||
},
|
},
|
||||||
|
Example {
|
||||||
|
description: "Use captures to manipulate the input text",
|
||||||
|
example: r#""abc-def" | str replace "(.+)-(.+)" "${2}_${1}""#,
|
||||||
|
result: Some(Value::test_string("def_abc")),
|
||||||
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Find and replace with fancy-regex",
|
description: "Find and replace with fancy-regex",
|
||||||
example: r#"'a successful b' | str replace '\b([sS])uc(?:cs|s?)e(ed(?:ed|ing|s?)|ss(?:es|ful(?:ly)?|i(?:ons?|ve(?:ly)?)|ors?)?)\b' '${1}ucce$2'"#,
|
example: r#"'a successful b' | str replace '\b([sS])uc(?:cs|s?)e(ed(?:ed|ing|s?)|ss(?:es|ful(?:ly)?|i(?:ons?|ve(?:ly)?)|ors?)?)\b' '${1}ucce$2'"#,
|
||||||
|
|
Loading…
Reference in a new issue