Community
    • Login

    help reg-ex

    Scheduled Pinned Locked Moved General Discussion
    5 Posts 2 Posters 643 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.
    • cisco779kC Offline
      cisco779k
      last edited by

      hi, i have long list as:

      mail001@host.net:password | txt = blabla | date = 1/23/20 | agage = UR
      mail002@hodf.nat:password | txt2 = blabla2 | date = 3/21/15 | agage = UX
      mail003@gajs.ned:password | txt3 = blasha | date = 9/03/19 | agage = AN
      

      and i want delete all text after mail:password like this:

      mail001@host.net:password
      mail002@hodf.nat:password
      mail003@gajs.ned:password
      

      very simple! but not for me… any help?
      tanxs to everubody

      astrosofistaA 1 Reply Last reply Reply Quote 0
      • astrosofistaA Offline
        astrosofista @cisco779k
        last edited by

        Hi @cisco779k

        As data provided, could be any of these three regexes. Just select Replace All where the \K is involved:

        Search: (?-s)\x20\|.*
        
        or
        
        Search: (?-s)^.+?\K.\|.*
        
        or
        
        Search: (?-s)^[^ |]+?\K |.*
        

        And leave the Replace field empty.

        Have fun!

        1 Reply Last reply Reply Quote 3
        • cisco779kC Offline
          cisco779k
          last edited by

          oh yes, all 3 regex work fine! many tanxs for your reply!
          just out of curiosity, what changes among the 3 regex?

          astrosofistaA 1 Reply Last reply Reply Quote 0
          • astrosofistaA Offline
            astrosofista @cisco779k
            last edited by

            Hi @cisco779k

            You’re welcome. The text you provided can be described as a bunch of lines with the following structure - A (the substring to be preserved) | (the first vertical bar) B (the substring to be deleted, which includes the vertical bar).

            So, the first regex provides a direct approach to delete B - it ignores A and matches from the space preceding the first vertical bar until the end of the line. The other regexes take into account A but defines it in different ways - the second regex can be described as “match all the characters from the start of the line but discard them —that’s the work of \K— as soon as a vertical bar is matched”, that is, reset the matching engine and as it keeps advancing, B is matched. The third regex works in a similar way but defines A as the complement of the class whose members are spaces and |.

            Lastly, all the three regexes require an empty replace field, so the matched substring or B is replaced with nothing, that is, is deleted.

            For a comprehensive FAQ, please follow this link.

            Have fun!

            1 Reply Last reply Reply Quote 1
            • cisco779kC Offline
              cisco779k
              last edited by

              many tanxs (again) for your explanation!

              1 Reply Last reply Reply Quote 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
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors