File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Java in General
Regular expression for numeric copy
Joined: Jul 10, 2001
Sep 04, 2008 08:56:00
If i have a
with both numeric and alpha characters, how do i copy only the numeric values in to a new string from original(using regex)?
Joined: Mar 10, 2008
Sep 04, 2008 09:05:00
That would be
(\d+)[\i] or [i]"(\\d+)"
as a Java-string.
If I give it the string "abc123def456ghi", I get 123 in group 0 and 456 in group 1.
your regexp online at
Joined: Feb 25, 2006
Sep 04, 2008 14:09:00
The easiest way would be to replace all non-digits from the original String:
String original = "ab12cd34ef56"; String digits = original.replaceAll("\\D", "");
[ September 04, 2008: Message edited by: Piet Verdriet ]
I agree. Here's the link:
subject: Regular expression for numeric copy
How to verify if value is numeric
simple regex problem
EL Coercion question
Another Dan's erroneous definition?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014