none
unable to trim encrypted string RRS feed

  • Question

  • I have got huge response in $a and I want to remove string {noformat}

    $a=@'archi: *{noformat}<<encryptedstring 200 char long>>{noformat}@' -split "`n"

    I have tried all below code but unable to remove the string also how to identity encrypted string 

    $a="{noformat}<<encryptedstring 200 char long>>{noformat}" $b=$a.TrimStart('{noformat}') $c=$b.TrimEnd('{noformat}') $a=$c echo $a

    OR

    $a= $a -replace ('{noformat}','')

    OR

    $a= $a -replace ('\{noformat\}','')


    $a= $a -replace ('{noformat}','')

    Friday, March 30, 2018 2:56 PM

Answers

  • It would be easier if you took time to learn PwoerShell instead of guessing.

    $a=$a -replace '\{noformat\}'

    Much of the issue is a poor understanding of PowerShell but the "RegEx" also requires some learning.  All special characters have to be escaped in a RegEx expression.

    Incorrect use of parens in a PowerShell command will cause bad behavior.


    \_(ツ)_/




    • Edited by jrv Friday, March 30, 2018 3:05 PM
    • Marked as answer by himanshu_kulkarni Thursday, April 12, 2018 5:26 AM
    Friday, March 30, 2018 3:01 PM
  • Regular expression substring extraction example:


    $a = '@
    archi: *{noformat}0123456789ABCDEF=={noformat}
    @'
    
    $encStr = $a | Select-String '{noformat}(.+){noformat}' | ForEach-Object {
      $_.Matches[0].Groups[1].Value
    }
    # Now $encStr contains '0123456789ABCDEF=='
    


    -- Bill Stewart [Bill_Stewart]


    Friday, March 30, 2018 3:06 PM
    Moderator

All replies

  • It would be easier if you took time to learn PwoerShell instead of guessing.

    $a=$a -replace '\{noformat\}'

    Much of the issue is a poor understanding of PowerShell but the "RegEx" also requires some learning.  All special characters have to be escaped in a RegEx expression.

    Incorrect use of parens in a PowerShell command will cause bad behavior.


    \_(ツ)_/




    • Edited by jrv Friday, March 30, 2018 3:05 PM
    • Marked as answer by himanshu_kulkarni Thursday, April 12, 2018 5:26 AM
    Friday, March 30, 2018 3:01 PM
  • Regular expression substring extraction example:


    $a = '@
    archi: *{noformat}0123456789ABCDEF=={noformat}
    @'
    
    $encStr = $a | Select-String '{noformat}(.+){noformat}' | ForEach-Object {
      $_.Matches[0].Groups[1].Value
    }
    # Now $encStr contains '0123456789ABCDEF=='
    


    -- Bill Stewart [Bill_Stewart]


    Friday, March 30, 2018 3:06 PM
    Moderator