chinnusaccount
chinnusaccount

Reputation: 229

Regular expression to find particular email addressses

I have a list of following email addresses,

[email protected],
[email protected],
[email protected]
[email protected] 
[email protected]

How can I validate these email addresses using following email address

test.*@khm.com

Here I need to get the o/p as

[email protected],
[email protected]

Upvotes: 0

Views: 67

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174706

Seems like you want something like this,

^test[^@\\s]*@dhm\\.com$

[^@]* Matches any character but not of @ zero or more times.

System.out.println("[email protected]".matches("test[^@\\s]*@dhm\\.com"));
System.out.println("[email protected]".matches("test[^@\\s]*@dhm\\.com"));
System.out.println("[email protected]".matches("test[^@\\s]*@dhm\\.com"));
System.out.println("[email protected]".matches("test[^@\\s]*@dhm\\.com"));

Output:

true
true
false
false

Upvotes: 1

Related Questions