Reputation: 51
I have two strings :
s = "aaaaaaa"
and
m = "a"
I want output as commonChars="a"
but i am getting commonChars="aaaaaaa"
and for s = "a"
m = "aaaa"
I want output commonChars="a"
Can anyone suggest me regular expression for that ?
My code is
String commonChars = s.replaceAll("[^" + m + "]", "");
Upvotes: 0
Views: 88