Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
Java in General
Regular expression for numeric copy
Kishore Dandu
Ranch Hand
Posts: 1934
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 326
I like...
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 266
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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 ]
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How to verify if value is numeric
simple regex problem
EL Coercion question
Another Dan's erroneous definition?
isNumeric()
More...