Matcher matcher = Pattern.compile("[0-9]").matcher("35423523");
matcher.matches()
- 現在是假
,但我需要matcher.matches() - true
- 因爲該字符串是所有數字
或例如
Pattern.compile("[0-9A-Za-z]").matcher("35dwedwfeASADdfd423523");
- 必須爲真
或Pattern.compile("[0-9]").matcher("354ccwq23523");
- 一定是假的 或Pattern.compile("[0-9a-z]").matcher("354ccwq23523");
- 必須是真實的
如何做到這一點?
我不明白爲什麼這會是必要的,但對錨的解釋可以發現[這裏](HTTP:/ /www.regular-expressions.info/anchors.html) – errieman 2013-04-11 08:36:20
對不起我的壞。混淆'.match'與'.find()'。 – npinti 2013-04-11 08:37:24