String emailAdress = "[email protected]";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 = "[email protected]";
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
提交
取消