亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從 matcher.group() 獲取字符串并將其存儲在 java 中的單獨字符串變量中?

如何從 matcher.group() 獲取字符串并將其存儲在 java 中的單獨字符串變量中?

天涯盡頭無女友 2023-03-23 13:58:09
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);


查看完整回答
反對 回復 2023-03-23
  • 1 回答
  • 0 關注
  • 129 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號