wood burning stoves 2.0*
The moose likes Java in General and the fly likes Regular expression for numeric copy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regular expression for numeric copy" Watch "Regular expression for numeric copy" New topic
Author

Regular expression for numeric copy

Kishore Dandu
Ranch Hand

Joined: Jul 10, 2001
Posts: 1934
If i have a string with both numeric and alpha characters, how do i copy only the numeric values in to a new string from original(using regex)?


Kishore
SCJP, blog
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

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.

You can test your regexp online at http://www.fileformat.info/tool/regex.htm.
Piet Verdriet
Ranch Hand

Joined: Feb 25, 2006
Posts: 266
The easiest way would be to replace all non-digits from the original String:


[ September 04, 2008: Message edited by: Piet Verdriet ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regular expression for numeric copy
 
Similar Threads
isNumeric()
simple regex problem
Another Dan's erroneous definition?
How to verify if value is numeric
EL Coercion question