replaceAll() method can be used to remove all non-numeric present in a variable using Apex in Salesforce.
Sample Code:
String str = 'abc123xyz!@#$%^&*()_+';
String myOutStr = str.replaceAll( '[^0-9]', '' );
System.debug(
' Output String: ' + myOutStr
);
