Je pense que ce RegEx devrait faire le travail
string pattern = @"\b\w{4}";
var text = "The quick brown fox jumps over the lazy dog";
Regex regex = new Regex(pattern);
var match = regex.Match(text);
while (match.Captures.Count != 0)
{
foreach (var capture in match.Captures)
{
Console.WriteLine(capture);
}
match = match.NextMatch();
}
// outputs:
// quic
// brow
// jump
// over
// lazy
Sinon, vous pouvez utiliser des modèles comme:
\b\w{1,4} => The, quic, brow, fox, jump, over, the, lazy, dog
\b[\w|\d]{1,4} => would also match digits
Mise à jour: ajouté un exemple complet pour C# et modifié le modèle légèrement. Également ajouté quelques modèles alternatifs.
Avez-vous besoin d'utiliser Regex? Cela pourrait être fait dans une ligne de Linq: 'String.Join (" ", input.Split (null, StringSplitOptions.RemoveEmptyEntries) .Sélectionnez (w => w.Substring (0, Math.Min (4, w.Length)) ». – Dai
@Dai Juste parce que OP a * une certaine expérience RegEx * – niksofteng
J'utilise Nintex pour terminer l'opération, donc je suis lié par RegEx – JeremyA1