Community
    • 登入

    Replace only specific word within quotes in Notepad++

    已排程 已置頂 已鎖定 已移動 Help wanted · · · – – – · · ·
    6 貼文 3 Posters 1.7k 瀏覽
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • Phat HuynhP
      Phat Huynh
      最後由 編輯

      hello everyone, I have the following lines and I would like to just target the “,” that are inside the quotes (ie “,”) and replace it with “;”. Is there a way to do that in Notepad++? Thanks.

      test,N,1,“abc,test”,def,3,test,2
      test3,N,2,“abc”,“def, ghi”,1656,test,
      etc…

      the result should be:

      test,N,1,“abc;test”,def,3,test,2
      test3,N,2,“abc”,“def; ghi”,1656,test,

      1 條回覆 最後回覆 回覆 引用 0
      • Terry RT
        Terry R
        最後由 編輯

        @Phat-Huynh said in Replace only specific word within quotes in Notepad++:

        I would like to just target the “,” that are inside the quotes (ie “,”) and replace it with “;”.

        Seems fairly simple. However since you have quotes in your example and did not insert them inside a black box potentially what is shown here may not be the same as you have.

        Using the Replace function we have
        Find What:(,“[^,”]*),([^”]*)
        Replace With:\1;\2

        So in the Find What field I copied what your posts shows for the quotes. Check the quotes against your data and if different replace them with what you actually have in the data. A quick test in the Replace function using JUST the Find button will immediately tell you if it does not work, hence the quotes will be the issue.

        In any future questions, when inserting examples, once inserted, select them and click on the </> button above the post window, this surrounds the examples in a black box.

        Terry

        1 條回覆 最後回覆 回覆 引用 2
        • Terry RT
          Terry R
          最後由 編輯

          @Terry-R said in Replace only specific word within quotes in Notepad++:

          Using the Replace function we have
          Find What:(,“[^,”]),([^”])
          Replace With:\1;\2

          Forgot to say that as this is a regular expression the search mode must be “regular expression”.

          Terry

          Phat HuynhP 1 條回覆 最後回覆 回覆 引用 0
          • Phat HuynhP
            Phat Huynh @Terry R
            最後由 編輯

            @Terry-R Thanks Terry. I did what you suggested and just got "Can’t find the text (,“[^,”]),([^”])
            screenshot below:
            alt text

            astrosofistaA 1 條回覆 最後回覆 回覆 引用 0
            • astrosofistaA
              astrosofista @Phat Huynh
              最後由 編輯

              Hi @Phat-Huynh

              As @Terry-R told you, a missmatching quote style will make the regex fail.

              So replace the curly quotes with straight quotes, as follows

               Find What:(,"[^,"]*),([^"]*)
               Replace With:\1;\2
              

              Rest assured, it worked here.

              Have fun!

              Phat HuynhP 1 條回覆 最後回覆 回覆 引用 2
              • Phat HuynhP
                Phat Huynh @astrosofista
                最後由 編輯

                @astrosofista @Terry-R Perfect, thank you so much, it worked! Cheers.

                1 條回覆 最後回覆 回覆 引用 1
                • 第一個貼文
                  最後的貼文
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors