Urgent Regualr Expression Help Needed
-
Hello, I need to know how to only match if a word does not appear before the selected word. For example, I have the sentence "there is a brown fox over there". The word I'm trying to match would be, say "fox". However, I only want to match "fox" if the word "brown" does not appear directly before it. Any help would be greatly appreciated. So the sentence above would not match, however the sentence "there is a fox over there" would match. Thanks folks! Brian Van Beek Here's my boring blog! [^] -- modified at 11:15 Monday 17th October, 2005
-
Hello, I need to know how to only match if a word does not appear before the selected word. For example, I have the sentence "there is a brown fox over there". The word I'm trying to match would be, say "fox". However, I only want to match "fox" if the word "brown" does not appear directly before it. Any help would be greatly appreciated. So the sentence above would not match, however the sentence "there is a fox over there" would match. Thanks folks! Brian Van Beek Here's my boring blog! [^] -- modified at 11:15 Monday 17th October, 2005
-
thanks! Brian Van Beek Here's my boring blog! [^]
-
Greeeg wrote:
That works
I highly doubt that! [^brown] means 'one character NOT any of (b,r,o,w,n)'. xacc-ide 0.0.99-preview5 now with C#, C, IL, XML, Nemerle, IronPython and Boo highlighting support!
-
Greeeg wrote:
That works
I highly doubt that! [^brown] means 'one character NOT any of (b,r,o,w,n)'. xacc-ide 0.0.99-preview5 now with C#, C, IL, XML, Nemerle, IronPython and Boo highlighting support!
-
Well, to be honest I was not completely sure about that. :-O How to do this correctly? I tried
(word){0}
, but that doesn't work.You need to use a Negative Lookbehind. (?<!brown)\s+fox
-
Well, to be honest I was not completely sure about that. :-O How to do this correctly? I tried
(word){0}
, but that doesn't work.Greeeg wrote:
How to do this correctly?
I would use explicit captures, eg:
(?<brown>brown)\s+(?<fox>fox)
Match m = Regex.Match();
return m.Groups["brown"].Success && !m.Groups["fox"].Success;or even easier:
return !Match("brown\s+fox");
xacc-ide 0.0.99-preview5 now with C#, C, IL, XML, Nemerle, IronPython and Boo highlighting support!