Problem using -replace when editing HTML file

This topic contains 1 reply, has 2 voices, and was last updated by  Max Kozlov 1 year ago.

  • Author
  • #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

    Max Kozlov

    what you try to achieve ?

    [regex]::Escape should have only one argument

    may be you want

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

You must be logged in to reply to this topic.