Use the following regex : [^ ]+(?<!\b[^ ]{10})\b
Explanation :
[^ ]+ means that you are looking for a sequence of non space
character
(?<! means that you are backtracking the previous sequence and you
want it NOT to match the following condition
\b this is to says that you sequence must start with a word
delimiter (here it is space, start of line, ....)
[^ ]{10} followed by 10 non space characters
) is the end of the backtracking
\b to be sure your word is complete and to avoid end of line
problems
Here an example to get the number of words wich are NOT with length 10 :
string mySentence="this is a sample sentence containing 2 words with 10
characters and 15 words with other size";
MessageBox.Show(Regex.Matches(mySentence,@"[^ ]+(?<!\b[^ ]{10})\b").Count+"
words without 10 characters length");
Here an example to get the words wich are NOT with length 10 :
string mySentence="this is a sample sentence containing 2 words with 10
characters and 15 words with other size";
Regex regex=new Regex(@"[^ ]+(?<!\b[^ ]{10})\b");
foreach(Match m in regex.Matches(mySentence)) MessageBox.Show(m.Value);
Hope it helps,
Ludovic SOEUR.
"Iwan Petrow" <xx****@abv.bg> a écrit dans le message de
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi,
I want to count words in a string which are NOT with length 10. For me
word is a sequence of symbols different from ' '. So I want to match
these words. I think that the pattern has to be something like that "[^
]{10}|[ ]" but with not somewhere.
How to set to match not this pattern? Or other ideas?
Thanks.