1 year ago

#384439

test-img

Kees Netelvrees

Switch - Regex --> Insert line (string) after match instead of before

Below is part of a switch part in my script:

switch -Regex -File $fileName  {
'^:61:([0-9]{1,6}).+D\d+\,?\d*NMSCaccount maintenance fee' {$date=$Matches[1];  $saved = $_; ":86:account maintenance fee - $date"; $_ } 
}

I am trying to add a line (the string that starts with :86: with a date added coming from the :61: line) after Regex matches the regex that starts with ^:61:. I do not understand why it inserts the string before the match instead of after. So the :86: string should be inserted after the :61: match, not before. How can I do that?

Is this caused by my insufficient understanding of Switch or insufficient understanding of regular expressions?

regex

powershell

insert

switch-statement

0 Answers

Your Answer

Accepted video resources