Community
    • Login

    Split string with quotes to new line

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 3 Posters 12.9k 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.
    • J
      JajinderK
      last edited by

      Hi there.

      I have a line in a text-file that containes 1 line with 100’s of keywords between quotes. Each keyword(s) between quotes need to be split to a new line.

      Textfile:

      "This" "is" "a list" "or" "a string of" "words" "in one" "line" "that" "I" "want to" "split." "Everything" "between the" "quotes" "should be" "on a new" "line" "including the quotes"
      

      Output should become:

      "This" 
      "is" 
      "a list" 
      "or" 
      "a string of" 
      "words" 
      "in one" 
      "line" 
      etc...
      

      I have tried some RegEx, but I’m a fullblown noob. It is probably cause my way of thinking and not to mention that I don’t understand/how to read 99% of the “commands”. (current state of short-term-memory also not helping at all)

      How would you tackle this? If you have a solution in RegEx can you please type your way of thinking to solve this? I might be asking for much, but I really want to understand.
      Thanks for the help in advance.

      1 Reply Last reply Reply Quote 1
      • guy038G
        guy038
        last edited by guy038

        Hello, @jajinderk and All,

        Very easy to achieve !

        • Open your file in Notepad++

        • Select your long line of words with double-quote delimiters

        • Open the Replace dialog ( Ctrl + H )

        • As the Find what : zone is selected with previous contents, replace it with the " " string ( or the "\x20" string )

        • Fill in the Replace with : zone with "\r\n" ( or "\n" if you deal with UNIX files )

        Note that you must insert the " chars in the Find what : and Replace with : fields

        • Untick all the box options, on the left side of the dialog

        • Select the Regular expression search mode

        • Click once only on the Replace All option ( Do not use the Replace button )


        So, from your INPUT text :

        "This" "is" "a list" "or" "a string of" "words" "in one" "line" "that" "I" "want to" "split." "Everything" "between the" "quotes" "should be" "on a new" "line" "including the quotes"
        

        You should get, immediately, this OUTPUT text :

        "This"
        "is"
        "a list"
        "or"
        "a string of"
        "words"
        "in one"
        "line"
        "that"
        "I"
        "want to"
        "split."
        "Everything"
        "between the"
        "quotes"
        "should be"
        "on a new"
        "line"
        

        Best Regards,

        guy038

        J 1 Reply Last reply Reply Quote 4
        • J
          JajinderK @guy038
          last edited by

          OMG! I’m overcomplicating thigs too much. Thank you soo much. I’ve been trying things for litterly hours and the solution was so simple…

          1000-thanks.

          mkupperM 1 Reply Last reply Reply Quote 1
          • mkupperM
            mkupper @JajinderK
            last edited by

            @JajinderK There is one more item to add to what @guy038 wrote which is to make sure that “In selection” is enabled. “In selection” causes the search/replace to only happen within the selected area when you use the “Replace All” button.

            If the selection is more than 1024 characters then “In selection” gets turned on automatically. The example you had posted with "This" "is" "a list" ... "including the quotes" the selection is 182 characters long meaning that “In selection” does not get turned on automatically and “Replace All” will do the the replacement on the entire file from that point on down or the entire file if “wrap around” is enabled.

            The odds are you likely were okay as it’s rare to see a quoted single space such as " " in a document.

            1 Reply Last reply Reply Quote 3
            • guy038G
              guy038
              last edited by guy038

              Hi, @jajinderk, @mkupper and All,

              @mkupper, it happened that, when I did the tests of my regex S/R, the In selection option was already ticked for some reason !

              But you’re right about it ! After additional tests, I suppose that the road map shiould be :

              • Open your file in Notepad++

              • Select your long line of words with double-quote delimiters

              • Open the Replace dialog ( Ctrl + H )

              • As the Find what : zone is selected with previous contents, replace it with the " " string ( or the "\x20" string )

              • Fill in the Replace with : zone with "\r\n" ( or "\n" if you deal with UNIX files )

              Note that you must insert the " chars in the Find what : and Replace with : fields

              • Tick, if necessary, the In selection option, on the right side of the dialog

              • Untick all the box options, on the left side of the dialog

              • Select the Regular expression search mode

              • Click once only on the Replace All option ( Do not use the Replace button )


              Luckily, as you said, a single space char, between two double-quotes, does occur very rarely !

              BR

              guy038

              J 1 Reply Last reply Reply Quote 2
              • J
                JajinderK @guy038
                last edited by

                @guy038 @mkupper Thank you both for the additional information.

                1 Reply Last reply Reply Quote 1
                • Terry RT Terry R referenced this topic on
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors