How to extract email address from String like below with delimiter as "AND" ?
String str="abb@AND.comANDbbb.comANDccc@xxd.AND";
How to extract email address from String like below with delimiter as "AND" ?
String str="abb@AND.comANDbbb.comANDccc@xxd.AND";
Try with following code segment,
public class TokenizerTest
{
private final String testStr = "abb@AND.comANDbbb.comANDccc@xxd.AND";
public static void main(String[] args)
{
TokenizerTest tst = new TokenizerTest();
tst.tokenize();
}
public void tokenize()
{
if(testStr != null)
{
Pattern p = Pattern.compile("[*]*AND*[^.AND]");
String[] tokens = testStr.split(p.pattern());
for(String token:tokens)
{
System.out.println(token);
}
}
}
}
It results in
abb@AND.com
bb.com
cc@xxd.AND
Short answer: Computer says no.
Based on the string you provided, it can probably not be done in a reliable way, since it is not clear what is an email address, and what is a delimiter. In fact, it is difficult to extract more than one or two valid email-addresses at all from that line.
I recommend you first check your dataset to see if it is corrupted, then find a way to use a different delimiter.