Remove All Special Characters From String In Apex

Sample Code:

String name = '{B]@i%s*w:?,-a$j#e)e(t! S^a.m}a]l[';
name = name.replaceAll('[^a-zA-Z0-9\\s+]', '');
System.debug('Name-' + name);

Output:

  • Naman Saraswat

    i dont want to remove dot from my string
    example-
    string a=’apex code—.text’
    i want output as -apex code.text