Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace all numbers in java string

Tags:

java

regex

I have string like this String s="ram123",d="ram varma656887" I want string like ram and ram varma so how to seperate string from combined string I am trying using regex but it is not working

PersonName.setText(cursor.getString(cursor.getColumnIndex(cursor
                .getColumnName(1))).replaceAll("[^0-9]+"));
like image 897
skyshine Avatar asked May 12 '14 11:05

skyshine


1 Answers

The correct RegEx for selecting all numbers would be just [0-9], you can skip the +, since you use replaceAll.

However, your usage of replaceAll is wrong, it's defined as follows: replaceAll(String regex, String replacement). The correct code in your example would be: replaceAll("[0-9]", "").

like image 61
Leandros Avatar answered Sep 19 '22 02:09

Leandros