作者superlubu (叔叔你人真好)
看板java
标题Re: [问题] java.util.regex.Pattern
时间Mon Oct 29 14:06:45 2012
※ 引述《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
1F:→ coolcomm:Creates a matcher that will match the given input 10/29 19:58
2F:→ coolcomm:against this pattern. 10/29 19:59
3F:→ coolcomm:这是Pattern.matcher()的解释 10/29 20:00
4F:→ superlubu:"will" match... 不过你不相信就算了吧。 10/29 23:04