@@ -56,6 +56,10 @@ function Update-PipeScript {
5656 # If provided, will replace regular expression matches.
5757 [Collections.IDictionary ]
5858 $RegexReplacement = [Ordered ]@ {},
59+
60+ # If provided, will replace regions.
61+ [Collections.IDictionary ]
62+ $RegionReplacement ,
5963
6064 # If provided, will remove one or more parameters from a ScriptBlock.
6165 [string []]
@@ -259,6 +263,30 @@ function Update-PipeScript {
259263 ) -join ' '
260264
261265 $text = $newScript
266+
267+ if ($RegionReplacement.Count ) {
268+ foreach ($regionName in $RegionReplacement.Keys ) {
269+ $replacementReplacer = $RegexReplacement [$regionName ]
270+ $RegionName = $RegionName -replace ' \s' , ' \s'
271+
272+ $regionReplaceRegex = [Regex ]::New("
273+ [\n\r\s]{0,} # Preceeding whitespace
274+ \#region # The literal 'region'
275+ \s{1,}
276+ (?<Name>$RegionName )
277+ (?<Content>
278+ (?:.|\s)+?(?=
279+ \z|
280+ ^\s{0,}\#endregion\s{1,}\k<Name>
281+ )
282+ )
283+ ^\s{0,}\#endregion\s{1,}\k<Name>
284+ " , ' Multiline,IgnorePatternWhitespace,IgnoreCase' , ' 00:00:05'
285+ )
286+ $RegexReplacement [$regionReplaceRegex ] = $replacementReplacer
287+ }
288+ }
289+
262290 if ($RegexReplacement.Count ) {
263291 foreach ($repl in $RegexReplacement.GetEnumerator ()) {
264292 $replRegex = if ($repl.Key -is [Regex ]) {
0 commit comments