Could you please tell why my regex pattern which works in String.matches() doesn’t split given string using String.split ?
Here is the code:
String text = "sdf.an@dfgdfg.com; sdfsdf@fdfd.erff";
String regex = "(\\b[\\w.%-]+@[\\w.]+\.[a-zA-Z]{2,4}\\b)([,;]\\s*\\b[\\w.%-]+@[\\w.]+\.[a-zA-Z]{2,4}\\b)*";
String [] emails = text.split(regex);
emails is empty 🙁
I believe that
String.splitneeds a delimiter not the whole pattern.In your case you can simply put this