您能告诉我为什么我在 String.matches()
中工作的正则表达式模式不能使用 String.split
分割给定的字符串吗?
这是代码:
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);
电子邮件
为空:(
最佳答案
我相信 String.split
需要一个分隔符而不是整个模式。
在你的情况下,你可以简单地把这个
text.split(";\\s*")
关于java - String.split() 不适用于我搜索逗号分隔项目的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9661431/