string input = "The quick brown fox jumps over the lazy dog."; string pattern = @"\b\w{2,3}\b"; Regex regex = new Regex(pattern); Match match = regex.Match(input); while (match.Success) { Console.WriteLine(match.Value); match = match.NextMatch(); }
string input = "The quick brown fox jumps over the lazy dog."; string pattern = @"\b\w{4}\b"; Regex regex = new Regex(pattern); Match match = regex.Match(input); while (match.Success) { Console.WriteLine(match.Value); match = match.NextMatch(); }This example searches for all words in the input string that are exactly 4 characters long. The output will be "quick", "brown", "jumps", "lazy". Package library: System.Text.RegularExpressions