2017-04-26 3 views
0

`Wie ersetzt man Zeichenfolgen einschließlich Sonderzeichen in HTML mit PowerShell?

Get-Content C:\Users\sfair\Documents\Frontline\report.htm | Out-File C:\Users\sfair\Documents\Frontline\report1.txt 
$editreport = C:\Users\sfair\Documents\Frontline\report1.txt 
$editreport -replace [regex]::Escape('employee(id','employee</th><th>id</th>') 
$editreport -replace [regex]::Escape('employeeType(id)','id') 
$editreport -replace [regex]::Escape('employee(','employee</td><td>') 
$editreport -replace [regex]::Escape(')</td>','</td>') 

` Ich erhalte eine ähnliche Meldung für alle vier Operationen ersetzen:

Cannot find an overload for "Escape" and the argument count: "2". 
At C:\Users\sfair\Documents\Frontline\still-trying1.ps1:40 char:1 
+ $editreport -replace [regex]::Escape('employee(id','employee</th><th> ... 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : NotSpecified: (:) [], MethodException 
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest 

enter image description here Ich habe eine HTML-Datei in Powershell erzeugt wird, in eine CSV-Lesen. Ich möchte den HTML-Code bearbeiten und eine Zeichenfolge durch eine andere ersetzen.

Beispiel: $ data -replace "Mitarbeiter (id", "Employeeid"

Diese in der folgenden Meldung führt:

Das Muster für reguläre Ausdrücke "Mitarbeiter (id", "Employeeid" ist nicht gültig

.
+1

Sie benötigen eine wörtliche Eingabemuster '$ data -replace [regex] :: Escape ('Mitarbeiter (id') zu entkommen,‘ empleieeid '' –

+0

Hier ist die Zeile, die ich jetzt verwende: – Steve

Antwort

1

einen umgekehrten Schrägstrich Verwenden von Sonderzeichen in einem regulären Ausdruck zu entkommen.

$data -replace 'employee\(id', 'employeeid' 
Verwandte Themen