Any ideas on the regex need to remove words of 3 letters or less? So it would find "ii it was bbb cat rat hat" etc but not "four, three, twos".
Regex to match words of length 1 to 3 would be \b\w{1,3}\b
, replace these matches with empty string.
Regex re = new Regex(@"\b\w{1,3}\b");
var result = re.Replace(input, "");
To also remove double spaces you could use:
Regex re = new Regex(@"\s*\b\w{1,3}\b\s*");
var result = re.Replace(input, " ");
(Altho it will leave a space at the beginning/end of string.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With