Results for “replace”
Small, practical examples. Search by task or narrow things down below.
Replace text in a string
Replace every occurrence of a substring and keep the result in a new string. The original string is unchanged.
string✓ Tested
Replace text using captured regex groups
C++: Numbered replacement groups can rearrange a known two-part name.
C++✓ Tested
Replace text with parameter expansion
Bash Scripts: Replace text with parameter expansion with a small standalone Bash program.
Bash Scripts✓ Tested
Replace text with sed
Replace all occurrences of the substring old on each line and print the transformed text without changing the input file.
sed✓ Tested
Replace the first match
Find and replace one literal substring in C++.
C++✓ Tested
Replace the URL of a configured remote
Git: set-url changes configuration without fetching or pushing any objects.
Git✓ Tested
Change a path’s extension
Change a path’s extension in a complete Rust program using the standard library.
Rust✓ Tested
Transform each regex match with a callback
JavaScript: A replacement callback computes the replacement separately for each match.
JavaScript✓ Tested
Transform each regex match with a callback
TypeScript: A replacement callback computes the replacement separately for each match.
TypeScript✓ Tested
Update one array item by its identifier
Update one array item by its identifier with a small React component and explicit browser behavior.
React✓ Tested
Calculate the greatest common divisor
C: Euclid’s algorithm repeatedly replaces a pair with the divisor and remainder.
C✓ Tested
Copy a file without replacing an existing destination
Java: Files.copy fails if the destination already exists unless replacement is explicitly enabled.
Java✓ Tested