Community
    • Login

    I needed a help in something

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    10 Posts 4 Posters 902 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.
    • mohammad Al-MaaitahM
      mohammad Al-Maaitah
      last edited by

      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:12345

      help me and thank you all

      Terry RT 1 Reply Last reply Reply Quote 1
      • Terry RT
        Terry R @mohammad Al-Maaitah
        last edited by

        @mohammad-Al-Maaitah

        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

        mohammad Al-MaaitahM 3 Replies Last reply Reply Quote 2
        • mohammad Al-MaaitahM
          mohammad Al-Maaitah @Terry R
          last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • mohammad Al-MaaitahM
            mohammad Al-Maaitah @Terry R
            last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • mohammad Al-MaaitahM
              mohammad Al-Maaitah @Terry R
              last edited by

              @Terry-R I only want the first part, which is before: to only contain 4 letters or less

              Terry RT 1 Reply Last reply Reply Quote 0
              • Terry RT
                Terry R @mohammad Al-Maaitah
                last edited by Terry R

                @mohammad-Al-Maaitah

                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

                mohammad Al-MaaitahM 2 Replies Last reply Reply Quote 2
                • mohammad Al-MaaitahM
                  mohammad Al-Maaitah @Terry R
                  last edited by PeterJones

                  @Terry-R
                  okay for example
                  this is the txt file

                  qwe:123456789
                  abc:1234
                  terry:1212pp 
                  

                  look before the ( : ) terry is not less than 5 char so in this case
                  the output will be just

                  abc: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 Reply Last reply Reply Quote 0
                  • mohammad Al-MaaitahM
                    mohammad Al-Maaitah @Terry R
                    last edited by

                    @Terry-R

                    [1] : [2]
                    [1] must be just less than 5 char

                    PeterJonesP 1 Reply Last reply Reply Quote 0
                    • PeterJonesP
                      PeterJones @mohammad Al-Maaitah
                      last edited by PeterJones

                      @mohammad-Al-Maaitah ,

                      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 Expression

                      original 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.

                      1 Reply Last reply Reply Quote 2
                      • guy038G
                        guy038
                        last edited by

                        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

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