I want to eliminate all single letter words from a string in Java using pattern matching. I've coded as follows:
String str = "P@";
//remove single char words and extra white spaces
inputStr = inputStr.replaceAll("\\b[\\w']{1}\\b", "").replaceAll("\\s+", " ").trim();
I'm expecting an output as P@ as the input is not a single letter word. But I'm getting output as @ because its eliminating P. So basically its considering only alphabetical characters for matching pattern. Whereas I want to match on the basis of length of the string entered.
Please help.