help reg-ex

  • hi, i have long list as: | 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:

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

  • Hi @cisco779k

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

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

    And leave the Replace field empty.

    Have fun!

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

  • 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!

  • many tanxs (again) for your explanation!

Log in to reply