Skip to content

Commit b90feda

Browse files
committed
Update Update-MatchInFile help to use -OldText instead of -Contains
1 parent 0360008 commit b90feda

1 file changed

Lines changed: 22 additions & 22 deletions

File tree

PowerShell.MCP/PlatyPS/en-US/Update-MatchInFile.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@ Update text file content using string literal or regex replacement
1414

1515
### Path
1616
```
17-
Update-MatchInFile [-Path] <String[]> [-Contains <String>] [-Pattern <String>] [-Replacement <String>]
17+
Update-MatchInFile [-Path] <String[]> [-OldText <String>] [-Pattern <String>] [-Replacement <String>]
1818
[-LineRange <Int32[]>] [-Encoding <String>] [-Backup] [-ProgressAction <ActionPreference>] [-WhatIf]
1919
[-Confirm] [<CommonParameters>]
2020
```
2121

2222
### LiteralPath
2323
```
24-
Update-MatchInFile -LiteralPath <String[]> [-Contains <String>] [-Pattern <String>] [-Replacement <String>]
24+
Update-MatchInFile -LiteralPath <String[]> [-OldText <String>] [-Pattern <String>] [-Replacement <String>]
2525
[-LineRange <Int32[]>] [-Encoding <String>] [-Backup] [-ProgressAction <ActionPreference>] [-WhatIf]
2626
[-Confirm] [<CommonParameters>]
2727
```
2828

2929
## DESCRIPTION
30-
Replaces matching text (literal or regex) within optional line range. Preserves file metadata (encoding, newlines). Use -Contains for literal string replacement or -Pattern for regex-based replacement with capture groups support.
30+
Replaces matching text (literal or regex) within optional line range. Preserves file metadata (encoding, newlines). Use -OldText for literal string replacement or -Pattern for regex-based replacement with capture groups support.
3131

3232
## EXAMPLES
3333

3434
### Example 1: Replace text
3535
```powershell
36-
Update-MatchInFile config.txt -Contains "debug=false" -Replacement "debug=true" # Literal
36+
Update-MatchInFile config.txt -OldText "debug=false" -Replacement "debug=true" # Literal
3737
Update-MatchInFile code.cs -Pattern "var (\w+)" -Replacement "string $1" # Regex with capture groups
3838
```
3939

@@ -69,21 +69,6 @@ Accept pipeline input: False
6969
Accept wildcard characters: False
7070
```
7171
72-
### -Contains
73-
Specifies a literal string to match in lines. Only lines containing this substring will be processed for replacement. Unlike -Pattern (which uses regex), -Contains performs simple substring matching without interpreting special characters. This is useful when filtering lines that contain regex metacharacters like '[', ']', '(', ')', '.', '*', '+', '?', ' ' without needing to escape them. When used with -Replacement but without -Pattern, the entire line containing the string is replaced.
74-
75-
```yaml
76-
Type: String
77-
Parameter Sets: (All)
78-
Aliases:
79-
80-
Required: False
81-
Position: Named
82-
Default value: None
83-
Accept pipeline input: False
84-
Accept wildcard characters: False
85-
```
86-
8772
### -Encoding
8873
Specifies the character encoding. If omitted, encoding is auto-detected and preserved. Supports: utf8, utf8bom, sjis, eucjp, jis, ascii, utf16, utf32, etc.
8974
@@ -205,6 +190,21 @@ Accept pipeline input: False
205190
Accept wildcard characters: False
206191
```
207192

193+
### -OldText
194+
Literal string to search for and replace. Use with -Replacement parameter. The matched text (not the entire line) is replaced. For regex-based replacement, use -Pattern instead.
195+
196+
```yaml
197+
Type: String
198+
Parameter Sets: (All)
199+
Aliases:
200+
201+
Required: False
202+
Position: Named
203+
Default value: None
204+
Accept pipeline input: False
205+
Accept wildcard characters: False
206+
```
207+
208208
### CommonParameters
209209
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
210210

@@ -222,14 +222,14 @@ BEST PRACTICE - Verify before and after:
222222

223223
1. Check current content: Show-TextFile config.js -Pattern "localhost"
224224

225-
2. Make the replacement: Update-MatchInFile config.js -Contains "localhost" -Replacement "production"
225+
2. Make the replacement: Update-MatchInFile config.js -OldText "localhost" -Replacement "production"
226226

227227
3. Verify the change: Show-TextFile config.js -Pattern "production"
228228

229229
CRITICAL - Handling special characters (dollar, braces, quotes):
230230

231231
When replacing code with special characters, ALWAYS use here-strings.
232-
Example: $old = @'...'@ and $new = @'...'@ then Update-MatchInFile file.cs -Contains $old -Replacement $new
232+
Example: $old = @'...'@ and $new = @'...'@ then Update-MatchInFile file.cs -OldText $old -Replacement $new
233233

234234
Here-strings (@'...'@) treat ALL characters literally.
235235

@@ -249,6 +249,6 @@ Regular expression mode:
249249
- Use for complex transformations
250250
- Test first: Show-TextFile -Pattern "regex"
251251
- Escape special regex chars: . * + ? [ ] ( ) { } ^ $ |
252-
- -Contains and -Pattern are mutually exclusive (cannot be used together)
252+
- -OldText and -Pattern are mutually exclusive (cannot be used together)
253253

254254
## RELATED LINKS

0 commit comments

Comments
 (0)