Java remove non numeric characters from string except x
use this: [^x0-9]
You may check it on http://gskinner.com/RegExr/
Your regex is
number.replaceAll("[^\\dxX]+", "");
No need to escape normal characters inside a character class. An improvement is also to have the quantifier +
after the character class, that way sequences of those characters are replaced at once and not each char on its own.
Read some regex basics on Xisb: What absolutely every Programmer should know about regular expressions