1

I am having trouble understanding why this negative lookahead pattern works, when it shouldn't.

struct(((?!union).)*)Blooo;

Test

struct  
{   
  union 
  {
    unsigned short int WOOF;
    struct
    {
      unsigned char ON  :1;
      unsigned char OFF :1;
      unsigned char NT0 :6;
      unsigned char NT1 :8;
    } MIM;
  } U1;
  union 
  {
    unsigned short int WOOF;
    struct
    {
      unsigned char DA  :1;
      unsigned char NT0 :7;
      unsigned char NT1 :8;
      } MIM;
    } U2;
} Blooo;

It only matches the second union (which is what i need) but i want to understand why does it do that. In my head it should be written like this to work..

struct(.*((?!union).)*)Blooo;

..because there are some characters between "struct" and "union". I tried the same thing with positive lookahead and then it does not work like this.

Thanks

ele lont
  • 429
  • 1
  • 4
  • 10
  • [`struct(((?!union).)*)Blooo;`](https://regex101.com/r/WBQgFc/1) matches `struct`, then any char that does not start a `union` char sequence, 0+ repetitions, up to the `Blooo;` substring. – Wiktor Stribiżew Dec 14 '17 at 11:38

0 Answers0