I am dealing with some cells where I have to extract certain letters from these cells. I want to replace a whole String with " " except from one single-standing character. The biggest challenge to me has been to tell my Regex code only to look for a single Char and remove everything else. To further elaborate and simplify; I need my Regex to replace everything with "" execept from a single character that standa ALONE (I.E white spaces left and right or linked to a number)
public class Main {
public static void main(String[] args) {
String test = "22A 302 abc";
String works = test.replaceAll("^\\w[\\s\\S]*", " ");
System.out.println(works);
//Desired result: A
}
}