• Login
Community
  • Login

Split string with quotes to new line

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
6 Posts 3 Posters 13.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 Sep 26, 2023, 11:13 AM

    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
    • G
      guy038
      last edited by guy038 Sep 26, 2023, 11:54 AM Sep 26, 2023, 11:48 AM

      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 Sep 26, 2023, 11:50 AM Reply Quote 4
      • J
        JajinderK @guy038
        last edited by Sep 26, 2023, 11:50 AM

        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.

        M 1 Reply Last reply Sep 26, 2023, 3:24 PM Reply Quote 1
        • M
          mkupper @JajinderK
          last edited by Sep 26, 2023, 3:24 PM

          @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
          • G
            guy038
            last edited by guy038 Sep 26, 2023, 6:15 PM Sep 26, 2023, 6:14 PM

            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 Sep 26, 2023, 7:30 PM Reply Quote 2
            • J
              JajinderK @guy038
              last edited by Sep 26, 2023, 7:30 PM

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

              1 Reply Last reply Reply Quote 1
              • T Terry R referenced this topic on Oct 29, 2023, 9:16 PM
              6 out of 6
              • First post
                6/6
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors