Need Guidance -- How can I find a specific line segment and remove all spaces and tabs from ONLY that segment.
-
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:ZZZI appreciate everyone’s time that is looking into this.
Cheers
-
@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 fieldemptyAs 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
\Kmeta 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 withEQDin then, it will not touch any line witheqdTerry
-
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
spaceortabulationcharacters may appear in theEQD......lines, the appropriate regex S/R is rather :SEARCH
(?-s)(?-i:^EQD|(?!\A)\G).*?\K\hREPLACE
Leave EMPTYBest Regards,
guy038
-
-
@guy038 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?
I welcome your feedback and thank you both again for your time.
-
@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\hYou 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
-