1
为什么此功能将返回"e10"
为true
? (这被认为是false
)我的isNumber正则表达式有什么问题?
public boolean isNumber(String s) {
String pattern = "\\s*[+-]?((\\d+.?\\d*)|.\\d+)(e[+-]?\\d+)?\\s*";
return s.matches(pattern);
}
为什么此功能将返回"e10"
为true
? (这被认为是false
)我的isNumber正则表达式有什么问题?
public boolean isNumber(String s) {
String pattern = "\\s*[+-]?((\\d+.?\\d*)|.\\d+)(e[+-]?\\d+)?\\s*";
return s.matches(pattern);
}
由于((\\d+.?\\d*)|.\\d+)
。第二部分表示.
- 任何事物的匹配器,以及\d+
- 至少一个数字。 如果您打算匹配实际的点字符,请改为使用\.
。
非常感谢。一世 –
如果@eavidan解决了您的问题,我肯定他会很感激,如果您通过点击绿色的选中标记来接受他的答案。 :) –
好吧不知道,谢谢你 –
没问题。你是那个人。 :)(注意,它也给了*你*一个声望提升,我们都喜欢的东西;)) –