• Login
Community
  • Login

Find and delete all text after //

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
7 Posts 4 Posters 2.4k 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.
  • A
    Andre Silva
    last edited by Aug 21, 2019, 11:58 AM

    Hello,

    I need to clean a large .txt file. See the example below:

    LINE01 //BLABLABLA01
    LINE02 //BLABLA
    (…)

    I want to delete all text and numbers after the “//” in a given line so it looks like this:

    LINE01
    LINE02
    (…)

    Thank you

    A S 2 Replies Last reply Aug 21, 2019, 12:15 PM Reply Quote 0
    • A
      Alan Kilborn @Andre Silva
      last edited by Alan Kilborn Aug 21, 2019, 12:16 PM Aug 21, 2019, 12:15 PM

      @Andre-Silva

      You probably want to eliminate spaces before the // as well.

      I’d try this:

      • Bring up the Replace window (ctrl+h).
      • Find what box: (?-s)(.*?)\s*//.*
      • Replace with box: \1
      • Search mode: Regular expression
      • Wrap around: ticked
      • Press the Replace All button.

      Learn more about this kind of searching/replacing here: https://notepad-plus-plus.org/community/topic/15765/faq-desk-where-to-find-regex-documentation

      1 Reply Last reply Reply Quote 2
      • S
        supasillyass @Andre Silva
        last edited by Aug 21, 2019, 12:22 PM

        @Andre-Silva

        1. Search
        2. Replace…
        3. Search Mode: Regular expression
        4. Find what: [ ]*//.*$
        5. Replace with: (empty string)
        6. Replace All

        https://www.regular-expressions.info/

        1 Reply Last reply Reply Quote 3
        • G
          guy038
          last edited by Aug 21, 2019, 3:32 PM

          Hi, @andre-silva, @alan-kilborn, @supasillyass and All

          Here is a third possible regex, just for fun !

          SEARCH (?-s)\h*//.*

          REPLACE Leave EMPTY

          Of course, we, all, suppose that, assuming the text :

          LINE01 //BLAB // LABLA01
          

          @andre-silva expect :

          LINE01
          

          and not :

          LINE01 //BLAB
          

          Cheers,

          guy038

          A 1 Reply Last reply Aug 21, 2019, 3:41 PM Reply Quote 1
          • A
            Alan Kilborn @guy038
            last edited by Aug 21, 2019, 3:41 PM

            @guy038 said:

            LINE01 //BLAB // LABLA01

            Apparently that nuance was forgotten by @supasillyass ! ;)

            S 1 Reply Last reply Aug 21, 2019, 4:14 PM Reply Quote 0
            • S
              supasillyass @Alan Kilborn
              last edited by Aug 21, 2019, 4:14 PM

              @Alan-Kilborn
              Try it 😉

              A 1 Reply Last reply Aug 21, 2019, 5:09 PM Reply Quote 2
              • A
                Alan Kilborn @supasillyass
                last edited by Aug 21, 2019, 5:09 PM

                @supasillyass said:

                Try it

                It works; apologies for the mistake.

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