One way to replace n times:
$test = "My name is Bob, her name is Sara."
[regex]$pattern = "name"
$pattern.replace($test, "baby", 1)
> My baby is Bob, her name is Sara
More Related Contents:
- How can you use an object’s property in a double-quoted string?
- Powershell: passing json string to curl
- How to escape special characters in PowerShell?
- Function return value in PowerShell
- Read file line by line in PowerShell
- how do I loop through a line from a csv file in powershell
- Access PSObject property indirectly with variable
- Is there a way to set a variable up to place output to stdout or null?
- Custom RoboCopy Progress Bar in PowerShell
- Executing an EXE file using a PowerShell script
- How to reference .NET assemblies using PowerShell
- Get current user’s credentials object in Powershell without prompting
- Redirect Write-Host statements to a file
- How to properly -filter multiple strings in a PowerShell copy script
- Write-Host vs Write-Information in PowerShell 5
- Methods to hex edit binary files via Powershell
- Unable to convert a string to an integer variable from DateTaken attribute on a JPG file
- How to Grant permission to user on Certificate private key using powershell?
- Using Invoke-Command -ScriptBlock on a function with arguments
- Powershell – Reboot and Continue Script
- Hashtables and key order
- How can I execute an external program with parameters in PowerShell?
- Should $null be on the left side of the equality comparison? (-eq with arrays)
- Does PowerShell support HashTable Serialization?
- How can I redirect stdout and stderr without polluting PowerShell error output
- Using Powershell environmental variables as strings when outputting files
- Create Outlook email draft using PowerShell
- Remove last line from file with Powershell
- Using –% in PowerShell
- Are the cmdlets in a pipeline executing in parallel?