---
title: "java利用正则截取字符串中的数--学习笔记"
author: "rfheh"
date: "2011-10-17T11:19:36Z"
tags: ["Java", "String", "正则表达式"]
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2011-10-17T11:19:36Z"
id: 1198249
url: "https://rfheh.iteye.com/blog/1198249"
---

java利用正则截取字符串中的数字
String str = "xxx第47297章33";       
 String regex = "\\d*";       
 Pattern p = Pattern.compile(regex);        
Matcher m = p.matcher(str);        
while (m.find()) {            
if (!"".equals(m.group()))              
  System.out.println("come here:" + m.group());     
   }

只能输入整数或小数的正则表达式
"^[0-9]+([.]{1}[0-9]+){0,1}$" :cry: 