I think this is what you are looking for:
FirstWord(?!.*ThirdWord).{1,25}SecondWord
This way you match FirstWord first. The look ahead then checks to see if there are any characters
ahead of it that also contain the word ThirdWord. If it finds ThirdWord with the optional
preceeding characters it imediately fails (actually it will look again for another instance of
FirstWord and then fail). If it doesn't fail it will then goes back to the end of FirstWord and
then continues from there. The next check is to see if you have your range of 1-25 characters
followed by SecondWord. If they are there then it succeeds.
Tome
http://www.pcdotcom.com
On 30 Mar 2006 20:57:22 -0800,
si************@hotmail.com wrote:
Hi All,
I want to capture a word which is in certain range from another word
only if a third word is not between them(anywhere in the range).
Regex r = new
Regex(@"(FirstWord.{1,25})*((?<!ThirdWord\s+)Seco ndWord)");
So it works fine for a string like this
FirstWord ThirdWord SecondWord
it works fine in this case and does not return me a match.
but lets say string is of this form
FirstWord ThirdWord SometingElse here SecondWord
than returns me a match .I wan it to not return me anything if there is
a "ThirdWord" any where in the that range.
Irrespective if it is just before "SecondWord" or any where else in
that range.
Thanks
KS