I needed a help in something
-
how can I sort a lines before char and delete others line which is not have the same length for example :
abcde:123456 > this one will be delete
abcd:12345
abc:12345
ab:12345
I want to save all before ( : ) and char less than 5 , < 5
so all others lines will be deleted and will still just lines which less than 5
abcd:12345
abc:12345
ab:12345help me and thank you all
-
It would appear your primary language isn’t english thus I’m not entirely sure what you need, but this will be a solution for what I think you want.
You need to delete lines that have 6 or more digits after the
:
.This solution uses the Mark function.
Find What:^[^:\r\n]+:\d{6,}
The search mode is regular expression and you need to also tick the button called “bookmark line”.
When you click “Mark All” a blue circle will appear in the left margin for those lines to be removed. You can then check those (if you want). To delete those lines, right click on one of the blue circles and select “Remove Bookmarked Lines”.Terry
-
This post is deleted! -
This post is deleted! -
@Terry-R I only want the first part, which is before: to only contain 4 letters or less
-
I am not sure of what you need. You need to describe the condition more fully. Maybe your original example wasn’t explicit enough.
Are you saying for all lines, you want to keep the line if the string before the
:
is 4 characters or less. What about the characters after the:
, do they matter?You could try
^[^:\r\n]{5,}:
Terry
-
@Terry-R
okay for example
this is the txt fileqwe:123456789 abc:1234 terry:1212pp
look before the ( : ) terry is not less than 5 char so in this case
the output will be justabc:1234 qwe:123456789
because before the ( : ) less than 5 char
—
moderator added code markdown around text; please don’t forget to use the
</>
button to mark example text as “code” so that characters don’t get changed by the forum, otherwise we just waste a lot of time because your data isn’t clear -
[1] : [2]
[1] must be just less than 5 char -
Unfortunately, the language barrier slowed things down. If you had done more examples in the first set of data (as is requested in the search/replace template), it might have been more obvious to @Terry-R that the character restriction was before the colon, not after the colon.
As such, you just need to modify the regex he gave you so that the character limits are on the first half rather than the second half of the match. Also, the match needs to include the newline at the end, so it can delete the line.
FIND =
^[^:\r\n]{5,}:.*$(\R|\Z)
REPLACE = empty
SEARCH MODE = Regular Expressionoriginal data (from both of your sets of example data):
abcde:123456 > this one will be deleted abcd:12345 abc:12345 ab:12345 qwe:123456789 abc:1234 terry:1212pp > so will this one
after replacement
abcd:12345 abc:12345 ab:12345 qwe:123456789 abc:1234
The better your example data, the easier it is for us to properly generate a regular expression that will work, without all this back-and-forth.
Quick explanation:
^[^\r\n]{5,}:
= matches 5 or more characters before the colon.*$
= matches the rest of the line(\R|\Z)
= matches the newline at the end of the line if there is one, or the end-of-file if you don’t have a newline at the end of your final line of data
The pieces of each of those sub-expressions can be further understood by reading the Online User Manual linked below.
----
Useful References
- Please Read Before Posting
- Template for Search/Replace Questions
- Formatting Forum Posts
- Notepad++ Online User Manual: Searching/Regex
- FAQ: Where to find other regular expressions (regex) documentation
----
Please note: This Community Forum is not a data transformation service; you should not expect to be able to always say “I have data like X and want it to look like Y” and have us do all the work for you. If you are new to the Forum, and new to regular expressions, we will often give help on the first one or two data-transformation questions, especially if they are well-asked and you show a willingness to learn; and we will point you to the documentation where you can learn how to do the data transformations for yourself in the future. But if you repeatedly ask us to do your work for you, you will find that the patience of usually-helpful Community members wears thin. The best way to learn regular expressions is by experimenting with them yourself, and getting a feel for how they work; having us spoon-feed you the answers without you putting in the effort doesn’t help you in the long term and is uninteresting and annoying for us.
-
Hello, @mohammad-Al-Maaitah, @terry-r, @Peterjones and All,
If we suppose that each line does NOT contain two or more colon chars (
:
), then the simple regex syntax, below, should be enough :SEARCH
(?-s)^.{5,}:.*\R?
REPLACE
Leave EMPTY
If several
colon
chars may exist in one line, we would have to distinguish between multiple cases ! But, this is on other story !Best Regards,
guy038