Problem using -replace when editing HTML file

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Max Kozlov Max Kozlov 3 weeks, 5 days ago.

  • Author
    Posts
  • #69678

    I want to replace some strings in a generated HTML file, including some tag edits. Below is the code I am using:

    $editreport -replace [regex]::Escape('employee(id','employeeid')
    $editreport -replace [regex]::Escape('employeeType(id)','id')
    $editreport -replace [regex]::Escape('employee(','employee')
    $editreport -replace [regex]::Escape(')','')
    

    I get the following errors (same message on all 4 replaces – below is one of them):

    Cannot find an overload for "Escape" and the argument count: "2".
    At line:1 char:1
    + $editreport -replace [regex]::Escape('employee`(id','employee ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodException
        + FullyQualifiedErrorId : MethodCountCouldNotFindBest
    
  • #69687
    Profile photo of Max Kozlov
    Max Kozlov
    Participant

    what you try to achieve ?

    [regex]::Escape should have only one argument
    https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.escape(v=vs.110).aspx

    may be you want

    $editreport -replace [regex]::Escape('employee(id'), 'employeeid'

You must be logged in to reply to this topic.