I am trying to match two string in Java which have an invalid whitespace or a funny character in play. I have tried couple of things and have captured my attempts in the code however, below does not work i.e. tester complains unmatched.
package org.example;
import java.lang.reflect.Array;
import java.util.Arrays;
public class Tester {
    public static void main(String[] args){
        String actual = "*** Transaction with whitespace character ****** for replacement ***";
        String expected = "*** Transaction with whitespace character ****** for replacement ***";
        actual = actual.replaceAll("\uFFFD", "");
        String re = "[^\\u0009\\u000A\\u000D\\u0020-\\uD7FF\\uE000-\\uFFFD\\u0001\\u0000-\\u0010\\uFFFF]";
        actual.replaceAll(re, "");
        String re1 = "[^\\x09\\x0A\\x0D\\x20-\\xD7FF\\xE000-\\xFFFD\\x10000-x10FFFF]";
        actual.replaceAll(re1, " ");
        actual.replaceAll("\u001E", "");
        //actual.replaceAll("\uFFFD", "\"");
        String re2 = "[^\u0009\r\n\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF]";
        actual.replaceAll(re2, "");
        actual = translate(actual);
        if(actual.equals(expected))
            System.out.println("Matched !! ");
        else
            System.out.println("Unmatched !!!");
    }
    static String translate(String input)
    {
        // Creating array of string length
        char[] output = new char[input.length()];
        for (int i = 0; i < input.length(); i++)
        {
            char tch = input.charAt(i);
            if (tch == 65533) // char �
                tch = (char)233; // é
            else
                output[i] = input.charAt(i);
        }
        return Arrays.toString(output);
    }
}
 
     
     
    