I\'m trying to get the first letter of each word in a string using regex, here is what I have tried:
public class Test
{
public static void main(String[]
(Disclaimer: I have no experience with Java, so if it handles regexes in ways that render this unhelpful, I apologize.)
If you mean getting rid of the spaces preceding the M and L, try adding optional whitespace at the end
(?<=[\\S])[\\S]+\\s*
However, this may add an extra space in the case of single-letter words. This may fix that:
(?<=[\\S])[\\S]*\\s*