tags:

views:

882

answers:

3

I have a long string. What is the regular expression to split the numbers into the array?

+1  A: 

Are you removing or splitting? This will remove all the non-numeric characters.

myStr = myStr.replaceAll( "[^\\d]", "" )
Stefan Kendall
+1  A: 

You will want to use the String class' Split() method and pass in a regular expression of "\D+" which will match at least one non-number.

myString.split("\\D+");
Stephen Mesa
This will remove all the numeric characters and give an array with all the non-numeric ones. It's exactly the opposite of the requested.
tangens
Whoops, I must have misinterpreted what the question was. In that case it would be the negated version of the regex, which is \\D+I will update my answer!
Stephen Mesa
+2  A: 
String.split("\\D+")
evelio