Re: [問題] java.util.regex.Pattern

看板java作者 (叔叔你人真好)時間13年前 (2012/10/29 14:06), 編輯推噓0(004)
留言4則, 2人參與, 最新討論串2/3 (看更多)
※ 引述《coolcomm (coolcomm)》之銘言: : http://ppt.cc/ZbBl : 24: : int number=Integer.parseInt(Pattern.compile("\\d*").matcher(capacity).group()); : 請問為什麼每次到了第24行就會拋出IllegalStateException? : 剛剛把這行分開來寫 結果更奇怪了 : Pattern pattern=Pattern.compile("\\d*"); //在這行就拋出IllegalStateException : 有人知道是發生什麼事嗎@@ 呃... 推文是我搞錯... 去看一次 API Matcher.group() : Returns the input subsequence matched by the previous match. 而 Pattern.matcher() method 回傳的 Matcher 物件, 是未曾開始進行 match 動作的 所以你的那段 code 會一直 return IllegalStateException: No match found. 至於怎樣才能讓 matcher 跑起來.... 再去看看 API 文件吧. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 147.8.127.102

10/29 19:58, , 1F
Creates a matcher that will match the given input
10/29 19:58, 1F

10/29 19:59, , 2F
against this pattern.
10/29 19:59, 2F

10/29 20:00, , 3F
這是Pattern.matcher()的解釋
10/29 20:00, 3F

10/29 23:04, , 4F
"will" match... 不過你不相信就算了吧。
10/29 23:04, 4F
文章代碼(AID): #1GZXpub_ (java)
文章代碼(AID): #1GZXpub_ (java)