String emailAdress = "yourname@yourdomin.com";Pattern emailAddress = Pattern.compile("(.*)(@)(.*)");Matcher matchEmailAddress = emailAddress.matcher(emailAdress);String secondPartOfEmail;while(matchEmailAddress.find()){ System.out.println(matchEmailAddress.group(1)); System.out.println(matchEmailAddress.group(3));}当我运行这个源代码时,输出是:你的名字yourdomin.com我想将yourdomain.com存储在字符串类型变量中以备后用。我的意思是 matchEmailAddress 匹配器中的 group(3)。我已经尝试过:String secondPartOfEmail = matchEmailAddress.group(3)但是发生了错误。
1 回答
MYYA
TA贡献1868条经验 获得超4个赞
假设您只想匹配一个电子邮件地址,您可以这样做:
String emailAdress = "yourname@yourdomin.com";
Pattern emailAddress = Pattern.compile("(.*)(@)(.*)");
Matcher matchEmailAddress = emailAddress.matcher(emailAdress);
matchEmailAddress.find(); //find the next substring matching your pattern
String secondPartOfEmail = matchEmailAddress.group(3);
添加回答
举报
0/150
提交
取消