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