---
title: "正则表达式:字符串判断是否为数字,包括浮点数,正数,负数"
author: "cbbs"
date: "2011-06-28T10:37:53Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2011-06-28T10:37:53Z"
id: 1107353
url: "https://cbbs.iteye.com/blog/1107353"
---

```
Pattern p1 = Pattern.compile("(-|[0-9])?[0-9]*(\\.?)[0-9]+"); // 非數字
Matcher m = p1.matcher(str);
boolean b = m.matches(); // matches() 尝试将整个区域与模式匹配
```