scripts

Set-RegexReplace.ps1

SYNOPSIS

Updates text found with Select-String, using a regular expression replacement template.

SYNTAX

Set-RegexReplace.ps1 [-Replacement] <String> [-InputObject <MatchInfo>] [-ProgressAction <ActionPreference>]
 [<CommonParameters>]

DESCRIPTION

EXAMPLES

EXAMPLE 1

)' README.md |Set-RegexReplace.ps1 "`$1 $(Get-Date) `$2"

Updates the generated date in README.md.

EXAMPLE 2

\d+</td>)' |Set-RegexReplace.ps1 '$1 align="right"$2'

<table> <colgroup><col/><col/></colgroup> <tr><th>Name</th><th>Length</th></tr> <tr><td>README.md</td><td align=”right”>21099</td></tr> </table>

PARAMETERS

-Replacement

A regular expression replacement string.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-InputObject

The output from Select-String.

Type: MatchInfo
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-ProgressAction

Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

Microsoft.PowerShell.Commands.MatchInfo containing a regex match than will be replaced.

OUTPUTS

System.String of the input string if the Select-String’s input was a string instead of a file.

(File changes will be saved back to the file.)

NOTES

https://docs.microsoft.com/dotnet/standard/base-types/substitutions-in-regular-expressions

Get-Encoding.ps1