1

I have a simple regex that detects 'domain.com' email addresses in any of the following formats:

user@domain.com
user.one@domain.com
user_one@domain.com
user-one@domain.com

The regex that makes this work for me is written as:

\b([a-z0-9_\.-]+)@domain.com

This expression will detect and match the first occurence of any of the above.

However, I'd like the regex to match only after, let's say, 10 occurences are detected.

For example, a user submits a document that contains 5 email addresses in the document. In this scenario, the expression should ignore the document. However, if the user submits a document with 10 or more email addresses in the document, then the expression should detect this.

I've tried a myriad of possible solutions using the {10,} quantifier, some of them examples taken from this site, but I'm thinking that it has something to do with the way I'm grouping the expression that is causing it to fail.

Your assistance will be greatly appreciated.

4

3 回答 3

0

您可以使用此正则表达式:

(?:[^@]+@\S+){10}\s+([\w.-]+)(?=@domain\.com)

现在,当您访问反向引用 #1 时,它会在恰好出现 10 次后为您提供电子邮件名称部分。

于 2013-10-22T09:34:24.570 回答
0

((yourregexp).*){10,}如果两个电子邮件地址之间可以有任何字符,请使用。

((\b([a-z0-9_\.-]+)@domain.com).*){10}
于 2013-10-22T09:34:26.710 回答
0

您可以为每个匹配的域使用一个计数器,然后当且仅当它至少匹配 10 次时才包含一个域。

于 2013-10-22T09:12:53.200 回答