I am trying to get struct names which are outside package and endpackage optional strings.
If there are no package and endpackage strings, then the script should return all the struct names.
This is my script:
import re
a = """
package new;
typedef struct packed
{
logic a;
logic b;
} abc_y;
typedef struct packed
{
logic a;
logic b;
} abc_t;
endpackage
typedef struct packed
{
logic a;
logic b;
} abc_x;
"""
print(re.findall(r'(?!package)*.*?typedef\s+struct\s+packed\s*{.*?}\s*(\w+);.*?(?!endpackage)*', a, re.MULTILINE|re.DOTALL))
This is the output:
['abc_y', 'abc_t', 'abc_x']
Expected output:
['abc_x']
I am missing something in the regex, but can't figure out what. Can someone please help me fixing this? Thanks in advance.