找到与特定正则表达式匹配的字符串,然后从该列表中排除任何符合一个或多个条件的内容

时间:2022-02-06 19:23:11

i'm using astrogrep to search email

我正在使用astrogrep来搜索电子邮件

to make it very tolerant i'm using this regex: [a-z0-9_.-]+@[a-z0-9_.-]+

让我非常宽容我正在使用这个正则表达式:[a-z0-9 _.-] + @ [a-z0-9 _.-] +

but I have to ignore some email from that search

但我不得不忽略该搜索的一些电子邮件

if i find ABCD or YXZ at the begining of the email, like ABCDsomething@something.com and YXZ something@something.com I have to exclude it from the result

如果我在电子邮件开头找到ABCD或YXZ,如ABCDsomething@something.com和YXZ something@something.com我必须将其从结果中排除

I have tried a fews things like;

我尝试了一些类似的事情;

(?!abcd)|([a-z0-9_.-]+)@[a-z0-9_.-]+
^(?!abcd+)|([a-z0-9_.-]+)@[a-z0-9_.-]+
(?!abcd)([a-z0-9_.-]+)@[a-z0-9_.-]+
(?!abcd+)([a-z0-9_.-]+)@[a-z0-9_.-]+

etc...

this seem easy when i did my search on google but it seem i cannot find a way to make it work

当我在谷歌搜索时,这似乎很容易,但似乎我找不到让它工作的方法

edit

create 3 text file in a folder first file contain 3 lines:

在文件夹中创建3个文本文件第一个文件包含3行:

abcdsomething@something.com
xyzsomething@something.com
something@something.com

abcdsomething@something.com xyzsomething@something.com something@something.com

second file 1 line

第二个文件1行

something@something.com

third file 3 lines

第三档3行

email1="abcdsomething@something.com"
email2="xyzsomething@something.com"
email3="something@something.com"

email1 =“abcdsomething@something.com”email2 =“xyzsomething@something.com”email3 =“something@something.com”

with astrogrep search that folder, case NOT sensitive

用astrogrep搜索那个文件夹,案例不敏感

expected result 1 email found in each file

预期结果每个文件中找到1封电子邮件

with [a-z0-9_.-]+@[a-z0-9_.-]+ i get all email properly but i just want to ignore the one that start with abcd / xyz

与[a-z0-9 _.-] + @ [a-z0-9 _.-] +我正确地收到所有电子邮件,但我只是想忽略以abcd / xyz开头的那个

2 个解决方案

#1


it seem that the answer was this \b(?!abcd|xyz)[a-z0-9_.-]+@[a-z0-9_.-]+

似乎答案是这个\ b(?!abcd | xyz)[a-z0-9 _.-] + @ [a-z0-9 _.-] +

#2


You can use negative lookahead like this:

您可以像这样使用负向前瞻:

(?!\b(abcd|xyz))[a-z0-9_.-]+@[a-z0-9_.-]+\b

This will fail the match if abcd or xyz is found at the start of input.

如果在输入开始时找到abcd或xyz,则匹配将失败。

#1


it seem that the answer was this \b(?!abcd|xyz)[a-z0-9_.-]+@[a-z0-9_.-]+

似乎答案是这个\ b(?!abcd | xyz)[a-z0-9 _.-] + @ [a-z0-9 _.-] +

#2


You can use negative lookahead like this:

您可以像这样使用负向前瞻:

(?!\b(abcd|xyz))[a-z0-9_.-]+@[a-z0-9_.-]+\b

This will fail the match if abcd or xyz is found at the start of input.

如果在输入开始时找到abcd或xyz,则匹配将失败。