-1

Lets say i have some random easy match like

\bword\b

Now i want to add to this that if before this match there is lets say this

(HOUSE[ ]*?)\bword\b

So if the word HOUSE and whatever ammount of spaces is infront of word then the match should be false. So my question more or less is how do i negate the (HOUSE[ ]*?) query?

Vajura
  • 1,112
  • 7
  • 16
  • it seems unclear for me. – Avinash Raj Jul 24 '14 at 11:12
  • 2
    You use a negative lookbehind. In .NET lookbehinds can be infinite AFAIK so: `(?<!HOUSE[ ]*?)\bword\b` should do the job – HamZa Jul 24 '14 at 11:15
  • yep. Post it as an answer. – Avinash Raj Jul 24 '14 at 11:16
  • +1 for @HamZa 's solution – zx81 Jul 24 '14 at 11:21
  • @HamZa hm i think it will work but i was kinda trying to avoid lookarounds. Guess there is no other solution – Vajura Jul 24 '14 at 11:27
  • @Vajura There should be another programmatic way. You use `(HOUSE[ ]*?)?\bword\b` and then check if group 1 exists. If it exists then the result should be false. Not sure how .NET handles the existence of group 1, but you could always check if it's empty or something like that. – HamZa Jul 24 '14 at 11:29
  • @HamZa I actualy came up with excatly this 1 minute ago i think i prefer this solution – Vajura Jul 24 '14 at 12:09

1 Answers1

2

You use a negative lookbehind. In .NET lookbehinds can be variable length:

(?<!HOUSE[ ]*?)\bword\b

Reference:

Community
  • 1
  • 1
HamZa
  • 14,671
  • 11
  • 54
  • 75