Powershell not finding substring with line-break

Hello There,
I was given the task to do some automatic content changes within the outlook signature files…
For the main part, all is working fine as they are just simple replacements. But in the .htm file, I do have a spot that gets generated by Outlook like this:

<p class=MsoNormal><b style='mso-bidi-font-weight:normal'><span
style='mso-ascii-font-family:Calibri;mso-hansi-font-family:Calibri'>Max
Mustermann<o:p></o:p></span></b></p>

My task is to replace the “Max Mustermann” in there with whatever Name I am given.
Also, this is:

  1. The only place where my code doesn’t work
  2. The only Occurrence where Outlook decides to put a line-break within the name

I do have tried many ways but have not found any solution. Some of my tries are in the following code snippet:

#read file
$text = Get-Content -Path $FilePath

#vars
$Name = Read-Host -Prompt "Enter Name"
...
#refining $Name
$NameArray = $Name.Split(' ')


#replacement stuff
$text = $text -replace '(?s)Max(?<space>.*?)Mustermann', ($NameArray[0] + '${space}' + $NameArray[1]) 
#Having to keep the spacer (like '%20' instead of ' ')

$text = $text.replace("Max
Mustermann", $Name)
#$text = $text -replace "Max`nMustermann", ($NameArray[0] + '`n' + $NameArray[1])
... #other replacements

Out-File -FilePath .\Result\default.htm -InputObject $text

I have also tried many variations of the above code as well as simply just to find that piece in the file.
And, I am using Powershell 5.1 (which is natively included in windows)

I hope, there is some way to fix this problem but anyways
Thanks for your help and your brain cells :wink:

elblorenz32,
Welcome to the forum. :wave:t4:

Sorry for the late answer. Nice nickname BTW. :wink:

I actually don’t understand your struggle.

$RawString = 
@'
<p class=MsoNormal><b style='mso-bidi-font-weight:normal'><span
style='mso-ascii-font-family:Calibri;mso-hansi-font-family:Calibri'>Max
Mustermann<o:p></o:p></span></b></p>
'@

$RawString -creplace 'Max\s+Mustermann', 'Maximilie Musterfrau'

If you read the strings from a file with Get-Content you may use the parameter -Raw to get the file in one piece and not split into single lines.

If that doesn’t help you may share your actual code and we can try to help you further. :love_you_gesture:t4:

Thank you,
Although it was late, you did still help me. ^^

It was indeed the -Raw parameter which I was missing, so PowerShell would look into all the lines but not from one line to the next

Fixed it, and now it’s working >_<

Oh, and my nickname is basically just the “nickname” of the city I live in with some changes to it :wink:

That’s what I thought and that’s why I liked it. :wink:

Greetings to Dresden. :wave:t3: