How to eliminate lines that meet a specific condition with Notepad?
-
Hi, friends I need to eliminate the lines that meet the following conditions
1john1:9678sharp
Karly:
woman:7890test
logomen:dream
:hitman
lvely:to
1john1:9678sharp
woman:7890test
logomen:dreamtry it with: (\s:.)([^\s]+) just delete the right side of “:”
Any friends idea?
-
Hi, @oscar-remiccc and All,
Apparently, I understand that you would like to delete every line, ending with the colon
:characterEasy, with regular expressions !
-
Open the Replace dialog
-
Select the
Regular expressionsearch mode -
Tick, if necessary, the
Wrap aroundoption
SEARCH
(?-s).*:\RREPLACE
Leave EMPTY- Click once, on the
Replace Allbutton or several times, on theReplacebutton
Notes :
-
The first part
(?-s)means that dot,., matches any single standard character, only ( not EOL ones ) -
The middle part
.*:tries to match the longest range of characters, even null, before a colon character -
The final part
\Rmatches any kind of line-break (\r\nin Windows files,\nin Unix files and\rin Mac files ) -
Note that the last line, of your file, must be followed with a line-break ( Just in case this last line would end with a colon character
:!
Cheers,
guy038
-
-
@guy038 said:
I understand that you would like to delete every line, ending the colon : character
:hitmandoesn’t end with a:(although it begins with one) and it appears to not be in the OP’s desired output…Maybe best to wait for OP’s clarification rather than guess, though.
-
thanks friends, excuse me for letting me understand
I need to eliminate lines that are not complete like this:Karly:
:hitman
lvely:example file containing :
1john1:9678sharp
Karly:
woman:7890test
logomen:dream
:hitman
lvely:Needed result:
1john1:9678sharp
woman:7890test
logomen:dreammy file contains more than 60000 lines
thanks you
-
Try this to do it all at once (…or use @guy038’s solution twice with a slight change for the second run):
Invoke Replace dialog (default key: ctrl+h)
Find what zone:^((:.+)|(.+:))(\R|\z)
Replace with zone: make sure this box is EMPTY
Wrap around checkbox: ticked
Search mode selection: Regular expression
Action: Press Replace All buttonHere’s how it works, the Find part anyway…the Replace part containing nothing simply removes the text matched by the Find part…note that I used capturing groups rather than non-capturing because the non-capturing symbology contains a
:and that probably would make things look more confusing because of the literal:in the data:^((:.+)|(.+:))(\R|\z)- [Assert position at the beginning of a line (at beginning of the string or after a line break character) (carriage return and line feed, form feed)][1 ]
^ - [Match the regex below and capture its match into backreference number 1][2 ]
((:.+)|(.+:))- [Match this alternative (attempting the next alternative only if this one fails)][3 ]
(:.+)- [Match the regex below and capture its match into backreference number 2][2 ]
(:.+)- [Match the colon character][4 ]
: - [Match any single character that is NOT a line break character (line feed, carriage return, form feed)][5 ]
.+- [Between one and unlimited times, as many times as possible, giving back as needed (greedy)][6 ]
+
- [Between one and unlimited times, as many times as possible, giving back as needed (greedy)][6 ]
- [Match the colon character][4 ]
- [Match the regex below and capture its match into backreference number 2][2 ]
- [Or match this alternative (the entire group fails if this one fails to match)][3 ]
(.+:)- [Match the regex below and capture its match into backreference number 3][2 ]
(.+:)- [Match any single character that is NOT a line break character (line feed, carriage return, form feed)][5 ]
.+- [Between one and unlimited times, as many times as possible, giving back as needed (greedy)][6 ]
+
- [Between one and unlimited times, as many times as possible, giving back as needed (greedy)][6 ]
- [Match the colon character][4 ]
:
- [Match any single character that is NOT a line break character (line feed, carriage return, form feed)][5 ]
- [Match the regex below and capture its match into backreference number 3][2 ]
- [Match this alternative (attempting the next alternative only if this one fails)][3 ]
- [Match the regex below and capture its match into backreference number 4][2 ]
(\R|\z)- [Match this alternative (attempting the next alternative only if this one fails)][3 ]
\R- [Match a line break (carriage return and line feed pair, sole line feed, sole carriage return, vertical tab, form feed)][7 ]
\R
- [Match a line break (carriage return and line feed pair, sole line feed, sole carriage return, vertical tab, form feed)][7 ]
- [Or match this alternative (the entire group fails if this one fails to match)][3 ]
\z- [Assert position at the very end of the string][8 ]
\z
- [Assert position at the very end of the string][8 ]
- [Match this alternative (attempting the next alternative only if this one fails)][3 ]
Created with RegexBuddy
[1 ]: http://www.regular-expressions.info/anchors.html
[2 ]: http://www.regular-expressions.info/brackets.html
[3 ]: http://www.regular-expressions.info/alternation.html
[4 ]: http://www.regular-expressions.info/characters.html
[5 ]: http://www.regular-expressions.info/dot.html
[6 ]: http://www.regular-expressions.info/repeat.html
[7 ]: http://www.regular-expressions.info/nonprint.html
[8 ]: http://www.regular-expressions.info/anchors.html#azRegexBuddy settings to emulate N++ regex engine: Application=boost::regex 1.54-1.57 / flavor=Default flavor / replacement flavor=All flavor / ^$ match at line breaks / Numbered capture / Allow zero-length matches
- [Assert position at the beginning of a line (at beginning of the string or after a line break character) (carriage return and line feed, form feed)][1 ]
-
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login