Loop search and replace two-part string over file using PowerShell while preserving one of the parts












2














I am new at PowerShell and have not found a Stack Overflow question or a documentation reference that gets me all the way to a successful outcome. If a question or documentation reference already exists that answers this that I overlooked I would be grateful to know.



In a text file is a string like this:



<span><span><span><span><span></span></span></span></span></span>


The number of <span> and </span> varies from file to file. For example, in some files it is like this:



<span></span>


Yet in others it is like this:



<span><span></span></span>


And so on. There are likely never going to be more than 24 of each in a string.



I want to eliminate all strings like this in the text file, yet preserve the </span> in strings like this:



<span style="font-weight:bold;">text</span>


There may be many variations on that kind of string in the text file; for example, <span style="font-size: 10px; font-weight: 400;">text</span> or <span style="font-size: 10px; font-weight: 400;">text</span> and I don't know beforehand what variation(s) will be included in the text file.



This partially works...



$original_file = 'in.txt'
$destination_file = 'out.txt'

(Get-Content $original_file) | Foreach-Object {
$_ -replace '<span>', '' `
-replace '</span>', ''
} | Set-Content $destination_file


...but obviously results in something like <span style="font-weight:bold;">text.



In the PowerShell script above I can use



    $_ -replace '<span></span>', '' `


But of course it only catches the <span></span> in the middle of the string because, as it is written now, it does not loop.



I know it is silly to do something like this



$original_file = 'in.txt'
$destination_file = 'out.txt'

(Get-Content $original_file) | Foreach-Object {
$_ -replace '<span></span>', '' `
-replace '<span></span>', '' `
-replace '<span></span>', '' `
-replace '<span></span>', '' `
-replace '<span></span>', ''
} | Set-Content $destination_file


So because the <span> string collapses into itself each time the script is run, producing a new inner <span></span> that can then be removed, the best solution I can think of is to loop the script over the file until it recognizes that all instances of <span></span> are gone.



I feel like adding logic along these lines is necessary:



   foreach($i in 1..24){
Write-Host $i


But have not been able to successfully incorporate it into the script.



If this is the wrong approach entirely I would be grateful to know.



The reason for PowerShell is that my team prefers it for scripts included in an Azure DevOps release pipeline.



Thanks for any ideas or help.










share|improve this question





























    2














    I am new at PowerShell and have not found a Stack Overflow question or a documentation reference that gets me all the way to a successful outcome. If a question or documentation reference already exists that answers this that I overlooked I would be grateful to know.



    In a text file is a string like this:



    <span><span><span><span><span></span></span></span></span></span>


    The number of <span> and </span> varies from file to file. For example, in some files it is like this:



    <span></span>


    Yet in others it is like this:



    <span><span></span></span>


    And so on. There are likely never going to be more than 24 of each in a string.



    I want to eliminate all strings like this in the text file, yet preserve the </span> in strings like this:



    <span style="font-weight:bold;">text</span>


    There may be many variations on that kind of string in the text file; for example, <span style="font-size: 10px; font-weight: 400;">text</span> or <span style="font-size: 10px; font-weight: 400;">text</span> and I don't know beforehand what variation(s) will be included in the text file.



    This partially works...



    $original_file = 'in.txt'
    $destination_file = 'out.txt'

    (Get-Content $original_file) | Foreach-Object {
    $_ -replace '<span>', '' `
    -replace '</span>', ''
    } | Set-Content $destination_file


    ...but obviously results in something like <span style="font-weight:bold;">text.



    In the PowerShell script above I can use



        $_ -replace '<span></span>', '' `


    But of course it only catches the <span></span> in the middle of the string because, as it is written now, it does not loop.



    I know it is silly to do something like this



    $original_file = 'in.txt'
    $destination_file = 'out.txt'

    (Get-Content $original_file) | Foreach-Object {
    $_ -replace '<span></span>', '' `
    -replace '<span></span>', '' `
    -replace '<span></span>', '' `
    -replace '<span></span>', '' `
    -replace '<span></span>', ''
    } | Set-Content $destination_file


    So because the <span> string collapses into itself each time the script is run, producing a new inner <span></span> that can then be removed, the best solution I can think of is to loop the script over the file until it recognizes that all instances of <span></span> are gone.



    I feel like adding logic along these lines is necessary:



       foreach($i in 1..24){
    Write-Host $i


    But have not been able to successfully incorporate it into the script.



    If this is the wrong approach entirely I would be grateful to know.



    The reason for PowerShell is that my team prefers it for scripts included in an Azure DevOps release pipeline.



    Thanks for any ideas or help.










    share|improve this question



























      2












      2








      2







      I am new at PowerShell and have not found a Stack Overflow question or a documentation reference that gets me all the way to a successful outcome. If a question or documentation reference already exists that answers this that I overlooked I would be grateful to know.



      In a text file is a string like this:



      <span><span><span><span><span></span></span></span></span></span>


      The number of <span> and </span> varies from file to file. For example, in some files it is like this:



      <span></span>


      Yet in others it is like this:



      <span><span></span></span>


      And so on. There are likely never going to be more than 24 of each in a string.



      I want to eliminate all strings like this in the text file, yet preserve the </span> in strings like this:



      <span style="font-weight:bold;">text</span>


      There may be many variations on that kind of string in the text file; for example, <span style="font-size: 10px; font-weight: 400;">text</span> or <span style="font-size: 10px; font-weight: 400;">text</span> and I don't know beforehand what variation(s) will be included in the text file.



      This partially works...



      $original_file = 'in.txt'
      $destination_file = 'out.txt'

      (Get-Content $original_file) | Foreach-Object {
      $_ -replace '<span>', '' `
      -replace '</span>', ''
      } | Set-Content $destination_file


      ...but obviously results in something like <span style="font-weight:bold;">text.



      In the PowerShell script above I can use



          $_ -replace '<span></span>', '' `


      But of course it only catches the <span></span> in the middle of the string because, as it is written now, it does not loop.



      I know it is silly to do something like this



      $original_file = 'in.txt'
      $destination_file = 'out.txt'

      (Get-Content $original_file) | Foreach-Object {
      $_ -replace '<span></span>', '' `
      -replace '<span></span>', '' `
      -replace '<span></span>', '' `
      -replace '<span></span>', '' `
      -replace '<span></span>', ''
      } | Set-Content $destination_file


      So because the <span> string collapses into itself each time the script is run, producing a new inner <span></span> that can then be removed, the best solution I can think of is to loop the script over the file until it recognizes that all instances of <span></span> are gone.



      I feel like adding logic along these lines is necessary:



         foreach($i in 1..24){
      Write-Host $i


      But have not been able to successfully incorporate it into the script.



      If this is the wrong approach entirely I would be grateful to know.



      The reason for PowerShell is that my team prefers it for scripts included in an Azure DevOps release pipeline.



      Thanks for any ideas or help.










      share|improve this question















      I am new at PowerShell and have not found a Stack Overflow question or a documentation reference that gets me all the way to a successful outcome. If a question or documentation reference already exists that answers this that I overlooked I would be grateful to know.



      In a text file is a string like this:



      <span><span><span><span><span></span></span></span></span></span>


      The number of <span> and </span> varies from file to file. For example, in some files it is like this:



      <span></span>


      Yet in others it is like this:



      <span><span></span></span>


      And so on. There are likely never going to be more than 24 of each in a string.



      I want to eliminate all strings like this in the text file, yet preserve the </span> in strings like this:



      <span style="font-weight:bold;">text</span>


      There may be many variations on that kind of string in the text file; for example, <span style="font-size: 10px; font-weight: 400;">text</span> or <span style="font-size: 10px; font-weight: 400;">text</span> and I don't know beforehand what variation(s) will be included in the text file.



      This partially works...



      $original_file = 'in.txt'
      $destination_file = 'out.txt'

      (Get-Content $original_file) | Foreach-Object {
      $_ -replace '<span>', '' `
      -replace '</span>', ''
      } | Set-Content $destination_file


      ...but obviously results in something like <span style="font-weight:bold;">text.



      In the PowerShell script above I can use



          $_ -replace '<span></span>', '' `


      But of course it only catches the <span></span> in the middle of the string because, as it is written now, it does not loop.



      I know it is silly to do something like this



      $original_file = 'in.txt'
      $destination_file = 'out.txt'

      (Get-Content $original_file) | Foreach-Object {
      $_ -replace '<span></span>', '' `
      -replace '<span></span>', '' `
      -replace '<span></span>', '' `
      -replace '<span></span>', '' `
      -replace '<span></span>', ''
      } | Set-Content $destination_file


      So because the <span> string collapses into itself each time the script is run, producing a new inner <span></span> that can then be removed, the best solution I can think of is to loop the script over the file until it recognizes that all instances of <span></span> are gone.



      I feel like adding logic along these lines is necessary:



         foreach($i in 1..24){
      Write-Host $i


      But have not been able to successfully incorporate it into the script.



      If this is the wrong approach entirely I would be grateful to know.



      The reason for PowerShell is that my team prefers it for scripts included in an Azure DevOps release pipeline.



      Thanks for any ideas or help.







      regex powershell






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 22:09









      LotPings

      17.2k61531




      17.2k61531










      asked Nov 10 at 17:41









      hcdocs

      1026




      1026
























          5 Answers
          5






          active

          oldest

          votes


















          1














          If you just want to remove any number of empty spans use a Regular Expression with a group and a quantifier:



          $original_file = 'in.txt'
          $destination_file = 'out.txt'

          (Get-Content $original_file) -replace "(<span>)+(</span>)+" |
          Set-Content $destination_file





          share|improve this answer





























            1














            Try the following .. i've added some comments to clearify things.



            # always use absolute paths if possible
            $original_file = 'c:tmpin.txt'
            $destination_file = 'c:tmpout.txt'

            $patternToBeRemoved = '<span></span>'

            # store the file contents in a variable
            $fileContent = Get-Content -Path $original_file

            # save the result of these operations in a new variable and iterate through each line
            $newContent = foreach($string in $fileContent) {
            # while the pattern you don't want is found it will be removed
            while($string.Contains($patternToBeRemoved)) {
            $string = $string.Replace($patternToBeRemoved, '')
            }
            # when it's no longer found the new string is returned
            $string
            }

            # save the new content in the destination file
            Set-Content -Path $destination_file -Value $newContent





            share|improve this answer





















            • Thank you for the explanatory comments @guenther
              – hcdocs
              Nov 18 at 18:31



















            0














            $original_file = 'in.txt'
            $destination_file = 'out.txt'

            ForEach ($Line in (Get-Content $original_file)) {
            Do {
            $Line = $Line -replace '<span></span>',''
            } While ($Line -match '<span></span>')
            Set-Content -Path $destination_file -Value $Line
            }





            share|improve this answer





























              0














              You can use a regular expression together with the -replace operator to strip all <span>optional content</span> pairs from a string. That means all pairs where the opening tag does not specify any attributes.



              $content = '<span></span><span><span><span style="font-weight:bold;">Foo</span></span></span>'
              $regex = '<span>(.*?)</span>'
              while ($content -match $regex)
              {
              $content = $content -replace $regex,'$1'
              }
              Write-Output $content


              The result will be:



              <span style="font-weight:bold;">Foo</span>


              The while loop takes care of your nested occurrences of the <span></span> pair.






              share|improve this answer































                0














                $content = '<span></span><span><span><span style="font-weight:bold;">Foo</span></span></span>'
                $regex = '<spans+[^<]+</span>'
                $null = $content -match $regex

                $Matches[0]





                share|improve this answer





















                • Welcome to Stack Overflow. While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value.How to Answer
                  – Elletlar
                  Nov 11 at 0:19











                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241692%2floop-search-and-replace-two-part-string-over-file-using-powershell-while-preserv%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                5 Answers
                5






                active

                oldest

                votes








                5 Answers
                5






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                1














                If you just want to remove any number of empty spans use a Regular Expression with a group and a quantifier:



                $original_file = 'in.txt'
                $destination_file = 'out.txt'

                (Get-Content $original_file) -replace "(<span>)+(</span>)+" |
                Set-Content $destination_file





                share|improve this answer


























                  1














                  If you just want to remove any number of empty spans use a Regular Expression with a group and a quantifier:



                  $original_file = 'in.txt'
                  $destination_file = 'out.txt'

                  (Get-Content $original_file) -replace "(<span>)+(</span>)+" |
                  Set-Content $destination_file





                  share|improve this answer
























                    1












                    1








                    1






                    If you just want to remove any number of empty spans use a Regular Expression with a group and a quantifier:



                    $original_file = 'in.txt'
                    $destination_file = 'out.txt'

                    (Get-Content $original_file) -replace "(<span>)+(</span>)+" |
                    Set-Content $destination_file





                    share|improve this answer












                    If you just want to remove any number of empty spans use a Regular Expression with a group and a quantifier:



                    $original_file = 'in.txt'
                    $destination_file = 'out.txt'

                    (Get-Content $original_file) -replace "(<span>)+(</span>)+" |
                    Set-Content $destination_file






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 11 at 13:12









                    LotPings

                    17.2k61531




                    17.2k61531

























                        1














                        Try the following .. i've added some comments to clearify things.



                        # always use absolute paths if possible
                        $original_file = 'c:tmpin.txt'
                        $destination_file = 'c:tmpout.txt'

                        $patternToBeRemoved = '<span></span>'

                        # store the file contents in a variable
                        $fileContent = Get-Content -Path $original_file

                        # save the result of these operations in a new variable and iterate through each line
                        $newContent = foreach($string in $fileContent) {
                        # while the pattern you don't want is found it will be removed
                        while($string.Contains($patternToBeRemoved)) {
                        $string = $string.Replace($patternToBeRemoved, '')
                        }
                        # when it's no longer found the new string is returned
                        $string
                        }

                        # save the new content in the destination file
                        Set-Content -Path $destination_file -Value $newContent





                        share|improve this answer





















                        • Thank you for the explanatory comments @guenther
                          – hcdocs
                          Nov 18 at 18:31
















                        1














                        Try the following .. i've added some comments to clearify things.



                        # always use absolute paths if possible
                        $original_file = 'c:tmpin.txt'
                        $destination_file = 'c:tmpout.txt'

                        $patternToBeRemoved = '<span></span>'

                        # store the file contents in a variable
                        $fileContent = Get-Content -Path $original_file

                        # save the result of these operations in a new variable and iterate through each line
                        $newContent = foreach($string in $fileContent) {
                        # while the pattern you don't want is found it will be removed
                        while($string.Contains($patternToBeRemoved)) {
                        $string = $string.Replace($patternToBeRemoved, '')
                        }
                        # when it's no longer found the new string is returned
                        $string
                        }

                        # save the new content in the destination file
                        Set-Content -Path $destination_file -Value $newContent





                        share|improve this answer





















                        • Thank you for the explanatory comments @guenther
                          – hcdocs
                          Nov 18 at 18:31














                        1












                        1








                        1






                        Try the following .. i've added some comments to clearify things.



                        # always use absolute paths if possible
                        $original_file = 'c:tmpin.txt'
                        $destination_file = 'c:tmpout.txt'

                        $patternToBeRemoved = '<span></span>'

                        # store the file contents in a variable
                        $fileContent = Get-Content -Path $original_file

                        # save the result of these operations in a new variable and iterate through each line
                        $newContent = foreach($string in $fileContent) {
                        # while the pattern you don't want is found it will be removed
                        while($string.Contains($patternToBeRemoved)) {
                        $string = $string.Replace($patternToBeRemoved, '')
                        }
                        # when it's no longer found the new string is returned
                        $string
                        }

                        # save the new content in the destination file
                        Set-Content -Path $destination_file -Value $newContent





                        share|improve this answer












                        Try the following .. i've added some comments to clearify things.



                        # always use absolute paths if possible
                        $original_file = 'c:tmpin.txt'
                        $destination_file = 'c:tmpout.txt'

                        $patternToBeRemoved = '<span></span>'

                        # store the file contents in a variable
                        $fileContent = Get-Content -Path $original_file

                        # save the result of these operations in a new variable and iterate through each line
                        $newContent = foreach($string in $fileContent) {
                        # while the pattern you don't want is found it will be removed
                        while($string.Contains($patternToBeRemoved)) {
                        $string = $string.Replace($patternToBeRemoved, '')
                        }
                        # when it's no longer found the new string is returned
                        $string
                        }

                        # save the new content in the destination file
                        Set-Content -Path $destination_file -Value $newContent






                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Nov 10 at 18:22









                        Guenther Schmitz

                        8701214




                        8701214












                        • Thank you for the explanatory comments @guenther
                          – hcdocs
                          Nov 18 at 18:31


















                        • Thank you for the explanatory comments @guenther
                          – hcdocs
                          Nov 18 at 18:31
















                        Thank you for the explanatory comments @guenther
                        – hcdocs
                        Nov 18 at 18:31




                        Thank you for the explanatory comments @guenther
                        – hcdocs
                        Nov 18 at 18:31











                        0














                        $original_file = 'in.txt'
                        $destination_file = 'out.txt'

                        ForEach ($Line in (Get-Content $original_file)) {
                        Do {
                        $Line = $Line -replace '<span></span>',''
                        } While ($Line -match '<span></span>')
                        Set-Content -Path $destination_file -Value $Line
                        }





                        share|improve this answer


























                          0














                          $original_file = 'in.txt'
                          $destination_file = 'out.txt'

                          ForEach ($Line in (Get-Content $original_file)) {
                          Do {
                          $Line = $Line -replace '<span></span>',''
                          } While ($Line -match '<span></span>')
                          Set-Content -Path $destination_file -Value $Line
                          }





                          share|improve this answer
























                            0












                            0








                            0






                            $original_file = 'in.txt'
                            $destination_file = 'out.txt'

                            ForEach ($Line in (Get-Content $original_file)) {
                            Do {
                            $Line = $Line -replace '<span></span>',''
                            } While ($Line -match '<span></span>')
                            Set-Content -Path $destination_file -Value $Line
                            }





                            share|improve this answer












                            $original_file = 'in.txt'
                            $destination_file = 'out.txt'

                            ForEach ($Line in (Get-Content $original_file)) {
                            Do {
                            $Line = $Line -replace '<span></span>',''
                            } While ($Line -match '<span></span>')
                            Set-Content -Path $destination_file -Value $Line
                            }






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 10 at 18:24









                            ErikW

                            947




                            947























                                0














                                You can use a regular expression together with the -replace operator to strip all <span>optional content</span> pairs from a string. That means all pairs where the opening tag does not specify any attributes.



                                $content = '<span></span><span><span><span style="font-weight:bold;">Foo</span></span></span>'
                                $regex = '<span>(.*?)</span>'
                                while ($content -match $regex)
                                {
                                $content = $content -replace $regex,'$1'
                                }
                                Write-Output $content


                                The result will be:



                                <span style="font-weight:bold;">Foo</span>


                                The while loop takes care of your nested occurrences of the <span></span> pair.






                                share|improve this answer




























                                  0














                                  You can use a regular expression together with the -replace operator to strip all <span>optional content</span> pairs from a string. That means all pairs where the opening tag does not specify any attributes.



                                  $content = '<span></span><span><span><span style="font-weight:bold;">Foo</span></span></span>'
                                  $regex = '<span>(.*?)</span>'
                                  while ($content -match $regex)
                                  {
                                  $content = $content -replace $regex,'$1'
                                  }
                                  Write-Output $content


                                  The result will be:



                                  <span style="font-weight:bold;">Foo</span>


                                  The while loop takes care of your nested occurrences of the <span></span> pair.






                                  share|improve this answer


























                                    0












                                    0








                                    0






                                    You can use a regular expression together with the -replace operator to strip all <span>optional content</span> pairs from a string. That means all pairs where the opening tag does not specify any attributes.



                                    $content = '<span></span><span><span><span style="font-weight:bold;">Foo</span></span></span>'
                                    $regex = '<span>(.*?)</span>'
                                    while ($content -match $regex)
                                    {
                                    $content = $content -replace $regex,'$1'
                                    }
                                    Write-Output $content


                                    The result will be:



                                    <span style="font-weight:bold;">Foo</span>


                                    The while loop takes care of your nested occurrences of the <span></span> pair.






                                    share|improve this answer














                                    You can use a regular expression together with the -replace operator to strip all <span>optional content</span> pairs from a string. That means all pairs where the opening tag does not specify any attributes.



                                    $content = '<span></span><span><span><span style="font-weight:bold;">Foo</span></span></span>'
                                    $regex = '<span>(.*?)</span>'
                                    while ($content -match $regex)
                                    {
                                    $content = $content -replace $regex,'$1'
                                    }
                                    Write-Output $content


                                    The result will be:



                                    <span style="font-weight:bold;">Foo</span>


                                    The while loop takes care of your nested occurrences of the <span></span> pair.







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Nov 10 at 18:49

























                                    answered Nov 10 at 18:19









                                    Manuel Batsching

                                    976412




                                    976412























                                        0














                                        $content = '<span></span><span><span><span style="font-weight:bold;">Foo</span></span></span>'
                                        $regex = '<spans+[^<]+</span>'
                                        $null = $content -match $regex

                                        $Matches[0]





                                        share|improve this answer





















                                        • Welcome to Stack Overflow. While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value.How to Answer
                                          – Elletlar
                                          Nov 11 at 0:19
















                                        0














                                        $content = '<span></span><span><span><span style="font-weight:bold;">Foo</span></span></span>'
                                        $regex = '<spans+[^<]+</span>'
                                        $null = $content -match $regex

                                        $Matches[0]





                                        share|improve this answer





















                                        • Welcome to Stack Overflow. While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value.How to Answer
                                          – Elletlar
                                          Nov 11 at 0:19














                                        0












                                        0








                                        0






                                        $content = '<span></span><span><span><span style="font-weight:bold;">Foo</span></span></span>'
                                        $regex = '<spans+[^<]+</span>'
                                        $null = $content -match $regex

                                        $Matches[0]





                                        share|improve this answer












                                        $content = '<span></span><span><span><span style="font-weight:bold;">Foo</span></span></span>'
                                        $regex = '<spans+[^<]+</span>'
                                        $null = $content -match $regex

                                        $Matches[0]






                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Nov 11 at 0:13









                                        walid

                                        1




                                        1












                                        • Welcome to Stack Overflow. While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value.How to Answer
                                          – Elletlar
                                          Nov 11 at 0:19


















                                        • Welcome to Stack Overflow. While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value.How to Answer
                                          – Elletlar
                                          Nov 11 at 0:19
















                                        Welcome to Stack Overflow. While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value.How to Answer
                                        – Elletlar
                                        Nov 11 at 0:19




                                        Welcome to Stack Overflow. While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value.How to Answer
                                        – Elletlar
                                        Nov 11 at 0:19


















                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.





                                        Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                        Please pay close attention to the following guidance:


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241692%2floop-search-and-replace-two-part-string-over-file-using-powershell-while-preserv%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        這個網誌中的熱門文章

                                        Tangent Lines Diagram Along Smooth Curve

                                        Yusuf al-Mu'taman ibn Hud

                                        Zucchini