Hello, I need to parse a variable definition in a string and want to do this with regex. I am programming in VB, but C#-solutions are welcome too.
Some of the possible sources:
DEF BOOL LB_TEST1
DEF BOOL LB_TEST2, LB_TEST3
DEF BOOL LB_TEST4[10], LB_TEST5[10,5]
DEF INT LI_TEST7
DEF INT LI_TEST8[3,4,5], LI_TEST9[3], LI_TEST10
DEF CHAN BOOL CB_TEMP1, CB_TEMP2
...
DEF NCK INT NI_TEMP5
...
As you can see, we start every time with
DEF
(thats the keyword for a definition)
Then comes (if not absent) a kind of scope
(nothing/CHAN/NCK)
Then follows the variables name, separated by commas. They also can have an array definition if they are not scalar.
The variables name must start with two chars or "_", then there can be numbers.
What I need is a list of all the variables per line, their datatype and array description:
BOOL LB_TEST1
BOOL LB_TEST2 and LB_TEST3
BOOL LB_TEST4 with 10 and LB_TEST5 with 10,5
INT LI_TEST7
INT LI_TEST8 with 3,4,5 and LI_TEST9 with 3 and LI_TEST10
...
I already have some RegEx, but it doesn't find the variables after the comma, that separates the variables. And there is perhaps a better way to solve the permutation problem of
DEF BOOL, DEF INT, DEF CHAN BOOL, DEF CHAN INT, DEF NCK BOOL, DEF NCK INT
(there are more datatypes like string, char, ...):
Here is my not properly working part:
\b(def\s+int|def\s+bool|def\s+chan\s+int|def\s+chan\s+bool|def\s+nck\s+int|def\s+nck\s+bool)\s+(?<names>([\w_]{2,}\d*(\[[\d,]+\])?[\,\s]?)+)
If I check this against
DEF INT LI_STRING1, LI_STRING2
it matches only
LI_STRING1
If I check this against
DEF INT LI_STRING1[34,5], LI_STRING2
it matches only
LI_STRING1 with 34,5
One essential part is working, but not the whole thing.
What am I doing wrong?
Thanks for any help in advance!
Greetings T_uRRiCA_N