help reg-ex
-
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 = ANand i want delete all text after mail:password like this:
mail001@host.net:password mail002@hodf.nat:password mail003@gajs.ned:passwordvery 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 Allwhere the\Kis involved:Search: (?-s)\x20\|.* or Search: (?-s)^.+?\K.\|.* or Search: (?-s)^[^ |]+?\K |.*And leave the
Replacefield 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 ignoresAand matches from the space preceding the first vertical bar until the end of the line. The other regexes take into accountAbut 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,Bis matched. The third regex works in a similar way but definesAas the complement of the class whose members arespacesand|.Lastly, all the three regexes require an empty
replacefield, so the matched substring orBis replaced with nothing, that is, is deleted.For a comprehensive FAQ, please follow this link.
Have fun!
-
many tanxs (again) for your explanation!