admin管理员组文章数量:1427995
I have a requirement where in a request containing field es in to my rest webservice.
In my webservice, I have to check for this field and if the validation for this passes, then I send the request to a third party service.
Validation Required:
message_from
field contains an email address
as string
. I have to check if the domain name
(everything after @
) is roin
For ex: [email protected]
passes, [email protected]
passes, [email protected]
fails...
Can I use pattern matchers or anything else to do this validation?
I have used string parsing to capture everything after (@)
and then did an equalsIgnoreCase
to pare it with roin
This string parsing approach works, but is there any better way to do this?
I have a requirement where in a request containing field es in to my rest webservice.
In my webservice, I have to check for this field and if the validation for this passes, then I send the request to a third party service.
Validation Required:
message_from
field contains an email address
as string
. I have to check if the domain name
(everything after @
) is roin.
For ex: [email protected]
passes, [email protected]
passes, [email protected]
fails...
Can I use pattern matchers or anything else to do this validation?
I have used string parsing to capture everything after (@)
and then did an equalsIgnoreCase
to pare it with roin.
This string parsing approach works, but is there any better way to do this?
Share Improve this question edited Oct 17, 2012 at 17:39 Rohit Jain 213k45 gold badges414 silver badges533 bronze badges asked Oct 17, 2012 at 17:22 user1717230user1717230 4531 gold badge15 silver badges31 bronze badges 1-
4
Why to use regex? Take the 9 last character of the string and check if they are
@roin.
– SJuan76 Commented Oct 17, 2012 at 17:26
1 Answer
Reset to default 6You can try this pattern (\\S+?@roin\\.)
: -
\\S+
is used to match any non-space character?
after\\S+
is used to do reluctant matching. It will match least number of character to satisfy the pattern\\.
is used to match.
- Since
.
is a special character in Regex, that is why we need to escape it to match it as literal.
So, here's the code: -
String str = "[email protected]";
Pattern pattern = Pattern.pile("\\S+?@roin\\.");
Matcher matcher = pattern.matcher(str);
if (matcher.matches()) {
System.out.println("Matches"); // Prints this for this email
}
本文标签: javaParsing Email Address to fetch domain and comparing itStack Overflow
版权声明:本文标题:java - Parsing Email Address to fetch domain and comparing it - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745510319a2661438.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论