• Login
Community
  • Login

help reg-ex

Scheduled Pinned Locked Moved General Discussion
5 Posts 2 Posters 300 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.
  • C
    cisco779k
    last edited by Nov 28, 2020, 8:42 AM

    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

    A 1 Reply Last reply Nov 28, 2020, 11:06 AM Reply Quote 0
    • A
      astrosofista @cisco779k
      last edited by Nov 28, 2020, 11:06 AM

      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
      • C
        cisco779k
        last edited by Nov 28, 2020, 1:30 PM

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

        A 1 Reply Last reply Nov 29, 2020, 12:29 PM Reply Quote 0
        • A
          astrosofista @cisco779k
          last edited by Nov 29, 2020, 12:29 PM

          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
          • C
            cisco779k
            last edited by Nov 29, 2020, 1:35 PM

            many tanxs (again) for your explanation!

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