Reputation: 682
I have an input string -
f.dollar_sales,f.unit_sales
I want to use String.replaceAll(regex,regex) method to get an output string as follows:
dollar_sales,unit_sales
I used the following:
fieldList.replaceAll("[a-zA-Z]\\Q.\\E"," ");
where fieldList is String variable where I've stored input String.
Can someone point out where I've made a mistake?
Upvotes: 1
Views: 2287
Reputation: 420
String is immutable, so you need to assign the updated string to that variable.
please run the below code;
public class StringReplace {
public static void main(String[] args){
String fieldList="f.dollar_sales,f.unit_sales";
fieldList=fieldList.replaceAll("[a-zA-Z]\\Q.\\E"," ");
System.out.println(fieldList);
}
}
Upvotes: 1
Reputation: 70732
You need to assign your replaced string and \Q
.. \E
is not necessary here.
fieldList = fieldList.replaceAll("[a-zA-Z]\\.", "");
Upvotes: 1