Community
    • Login

    Replace only specific word within quotes in Notepad++

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 3 Posters 1.5k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Phat HuynhP
      Phat Huynh
      last edited by

      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 Reply Last reply Reply Quote 0
      • Terry RT
        Terry R
        last edited by

        @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 Reply Last reply Reply Quote 2
        • Terry RT
          Terry R
          last edited by

          @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 Reply Last reply Reply Quote 0
          • Phat HuynhP
            Phat Huynh @Terry R
            last edited by

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

            astrosofistaA 1 Reply Last reply Reply Quote 0
            • astrosofistaA
              astrosofista @Phat Huynh
              last edited by

              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 Reply Last reply Reply Quote 2
              • Phat HuynhP
                Phat Huynh @astrosofista
                last edited by

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

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors