• Login
Community
  • Login

How to find the first space in all lines?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
6 Posts 2 Posters 715 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.
  • E
    Emalino Emalero
    last edited by Emalino Emalero Oct 28, 2023, 6:37 PM Oct 28, 2023, 4:02 PM

    I have a txt file with more than 3 thousand lines, I want to detect the first space in all lines and add a ]
    Original file format

    [fgggj oooo m6cmp5
    [5jgidd udd64j kkrt7 8d66sdjnd
    [hfhfh maoerchgu 996d63542
    [mmnkiiuy45 oiudzzc3

    Would be like this

    [fgggj]oooo m6cmp5
    [5jgidd]udd64j kkrt7 8d66sdjnd
    [hfhfh]maoerchgu 996d63542
    [mmnkiiuy45]oiudzzc3

    Next, use a regex that eliminates everything outside []

    Final result

    [fgggj]
    [5jgidd]
    [hfhfh]
    [mmnkiiuy45]

    It’s possible? Thank you for any help.

    C 1 Reply Last reply Oct 28, 2023, 4:11 PM Reply Quote 0
    • C
      Coises @Emalino Emalero
      last edited by Oct 28, 2023, 4:11 PM

      @Emalino-Emalero

      Find what : ^(\S++)[^\r\n]++
      Replace with : $1]

      E 1 Reply Last reply Oct 28, 2023, 4:27 PM Reply Quote 1
      • E
        Emalino Emalero @Coises
        last edited by Oct 28, 2023, 4:27 PM

        Thank you very much, Coises. It worked perfectly, saved my weekend! I applied the regex, using Linux Debian Sid, Notepad++ running via wine. Sorted out!

        1 Reply Last reply Reply Quote 0
        • E
          Emalino Emalero
          last edited by Emalino Emalero Oct 28, 2023, 4:59 PM Oct 28, 2023, 4:51 PM

          Sorry to bother you, but I have a question that I may need in the future. If I wanted to do the opposite, in the end result removing everything inside [] including [] itself, would it be possible? The end result would be this:

          oooo m6cmp5
          udd64j kkrt7 8d66sdjnd
          maoerchgu 996d63542
          oiudzzc3

          C 1 Reply Last reply Oct 28, 2023, 10:41 PM Reply Quote 0
          • C
            Coises @Emalino Emalero
            last edited by Oct 28, 2023, 10:41 PM

            @Emalino-Emalero said in How to find the first space in all lines?:

            Sorry to bother you, but I have a question that I may need in the future. If I wanted to do the opposite, in the end result removing everything inside [] including [] itself, would it be possible? The end result would be this:

            Find what : ^(\S++)\h
            Replace with : (empty)

            1 Reply Last reply Reply Quote 0
            • E
              Emalino Emalero
              last edited by Oct 29, 2023, 12:31 PM

              Thanks!

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