Word
A family of Microsoft word processing software products for creating web, email, and print documents.
890 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
$documentText = @"
Frau
Anna Mustermanowa
Hauptstr. 1
48996 Ministadt
per beA
per Mail: anna.mustermanowa@example.com
AKTEN.NR: SACHBEARBEITER/SEKRETARIAT STÄDTL,
2904/24/SB Sonja Bearbeinenko +49 211 123190.00 21.11.2024
Telefax: +49 211 123190.00
E-Mail: anwalt@ra.example.com
Superman ./. Mustermanowa
Worum es da so geht
Sehr geehrte Frau Mustermanowa,
"@
$Mandant = [regex]::match($documentText, '[^\r\n].*(?=\.\/\.)').Value
$Gegner = [regex]::match($documentText, '(?<=\.\/\.\s)[^\r\n]*').Value
$Az = [regex]::match($documentText, '\d{4}/\d{2}').Value
Write-Output "$Mandant"
Write-Output "./."
Write-Output "$Gegner"
Write-Output "$Az"
outputs
Superman
./.
Mustermanowa
2904/24
whereas
$wordApp = [Runtime.Interopservices.Marshal]::GetActiveObject('Word.Application')
$doc = $wordApp.ActiveDocument
$documentText = $doc.Content.Text
Set-Content -Path "debug.txt" -Value $documentText -Encoding UTF8
$Mandant = [regex]::match($documentText, '[^\r\n].*(?=\.\/\.)').Value
$Gegner = [regex]::match($documentText, '(?<=\.\/\.\s)[^\r\n]*').Value
$Az = [regex]::match($documentText, '\d{4}/\d{2}').Value
Write-Output "$Mandant"
Write-Output "./."
Write-Output "$Gegner"
Write-Output "$Az"
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($wordApp) | Out-Null
outputs
Superman -Mail: anwalt@ra.example.com0.0049 211 123190.00 21.11.2024
./.
Mustermanowa
2904/24
here-string from the first example is generated via Set-Content -Path "debug.txt" -Value $documentText -Encoding UTF8
from the second one.
How do I achieve the same Content.Text special symbols and line breaks structure inside a variable as is archievable by Set-Content'ing it into a text file?
Basically I want the same regex behaviour in the second code sample as in the first one.