• Login
Community
  • Login

Need Guidance -- How can I find a specific line segment and remove all spaces and tabs from ONLY that segment.

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
6 Posts 3 Posters 680 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
    John Tee
    last edited by Sep 27, 2021, 7:17 PM

    Ex. I want to find all “EQD” lines and remove all spaces and tabs from JUST those lines.

    See below sample data, as you can see 2 of the 3 EQD lines have a space. I need to remove any “space” or “tab” from just that line.

    EQD+CN+ZMLU XXXXXXX+45GP+++5
    NAD+CA+ZMLU:172:ZZZ
    LOC+147+0260808::5
    FTX+AAA+++ALUMINUM ARTICLES
    MEA+WT++KGM:16549
    LOC+9+DOHAI:139:6
    LOC+11+USSAV:139:6
    RFF+BM:1
    EQD+CN+ZMLU XXXXXXX+45GP+++5
    NAD+CA+ZMLU:172:ZZZ
    LOC+147+0260202::5
    FTX+AAA+++ALCOHOLIC BEVERAGES
    MEA+WT++KGM:27797
    LOC+9+JMKIN:139:6
    LOC+11+USSAV:139:6
    RFF+BM:1
    EQD+CN+ZMLUXXXXXXX+45GP+++5
    NAD+CA+ZMLU:172:ZZZ

    I appreciate everyone’s time that is looking into this.

    Cheers

    1 Reply Last reply Reply Quote 0
    • T
      Terry R
      last edited by Terry R Sep 27, 2021, 7:33 PM Sep 27, 2021, 7:32 PM

      @John-Tee said in Need Guidance -- How can I find a specific line segment and remove all spaces and tabs from ONLY that segment.:

      I want to find all “EQD” lines and remove all spaces and tabs from JUST those lines.

      Using the Replace function we have:
      Find What:(?-is)(?=^EQD).*?\K\h
      Replace With:nothing in this field empty

      As this is a regular expression the search mode MUST be regular expression and you must use the “Replace All” button as I have used the \K meta character in the expression. Run it multiple times if any line has more than 1 instance of a blank space or tab (you can see when it’s completed when the Replace Window states “0 occurances were replaced in entire file”. This expression will remove ONLY one at a time from each of the lines with EQD in then, it will not touch any line with eqd

      Terry

      1 Reply Last reply Reply Quote 2
      • G
        guy038
        last edited by Sep 27, 2021, 8:17 PM

        Hello, @john-tee, @terry-r and All,

        Ah, yes, @terry-r, we may also use this variation :

        (?-is)^(?=EQD).*?\K\h


        Now, if more than one horizontal blank char is present, in a line beginning with EQD, these two syntaxes do not work !

        In that case, we need to use the generic regex, belox, discussed in other posts, like this one :

        https://community.notepad-plus-plus.org/post/62799

        SEARCH (?-i:BSR|(?!\A)\G)(?s:(?!ESR).)*?\K(?-i:FR)

        REPLACE RR

        where :

        • FR (Find Regex ) is the regex which defines the char, string or expression to be searched

        • RR (Replacement Regex ) is the regex which defines the char, string or expression which must replace the FR expression

        • BSR ( Begin Search-region Regex ) is the regex which defines the beginning of the area where the search for FR, must start

        • ESR ( End Search-region Regex) is the regex which defines, implicitly, the area where the search for FR, must end


        For @John-Tee’s need, we have :

        • FR = \h

        • RR = Empty string

        • BSR = ^EQD

        • ESR is implicit and we don’t need the (?s:(?!ESR).)*? syntax . Indeed, due to the (?-s) modifier, the range of chars, matched with the part .*? cannot go beyond the current line, anyway, as the line-break char(s) are not allowed !

        Thus, if several space or tabulation characters may appear in the EQD...... lines, the appropriate regex S/R is rather :

        SEARCH (?-s)(?-i:^EQD|(?!\A)\G).*?\K\h

        REPLACE Leave EMPTY

        Best Regards,

        guy038

        J 1 Reply Last reply Sep 28, 2021, 2:18 PM Reply Quote 3
        • J
          John Tee @guy038
          last edited by John Tee Sep 28, 2021, 2:19 PM Sep 28, 2021, 2:18 PM

          @guy038 said in Need Guidance -- How can I find a specific line segment and remove all spaces and tabs from ONLY that segment.:

          @guy038 @Terry-R

          Is there a way to adjust the provided SEARCH: " (?-s)(?-i:^EQD|(?!\A)\G).*?\K\h " to further clean spaces and tabs for all the following lines at once: EQD, NAD, LOC, MAE, RFF - but don’t touch line FTX?

          I welcome your feedback and thank you both again for your time.

          1 Reply Last reply Reply Quote 0
          • T
            Terry R
            last edited by Sep 28, 2021, 7:53 PM

            @John-Tee said in Need Guidance -- How can I find a specific line segment and remove all spaces and tabs from ONLY that segment.:

            Is there a way to adjust the provided SEARCH: " (?-s)(?-i:^EQD|(?!\A)\G).*?\K\h " to further clean spaces and tabs for all the following lines at once: EQD, NAD, LOC, MAE, RFF - but don’t touch line FTX?

            Certainly. The changes are:
            for my regex it becomes (I made an additional change putting the ^ outside of the lookahead)
            (?-is)^(?=EQD|NAD|LOC|MAE|RFF).*?\K\h
            and for @guy038 regex it would be
            (?-s)(?-i:^(EQD|NAD|LOC|MAE|RFF)|(?!\A)\G).*?\K\h

            You can easily see how it expands to any additional codes, so if you need to change it, you should be able to do so easily. Try that.

            Terry

            J 1 Reply Last reply Sep 29, 2021, 6:23 PM Reply Quote 2
            • J
              John Tee @Terry R
              last edited by Sep 29, 2021, 6:23 PM

              @Terry-R Thank you very much the new update works great just what I needed. All the best and thank you @Terry-R and @guy038 for your time and guidance. Cheers

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