6972Honza
6972Honza

Reputation: 33

C# RegEx get attributes from CREATE TABLE

I need a RegEx to get name of table, keys and every attribute from CREATE TABLE statement... for example: Here I create this table, and i need to get all attributes

​CREATE
​  TABLE KATEGORIE
​  (
​    id INTEGER NOT NULL ,
​    nazev NVARCHAR (20) NOT NULL ,
​    cena INTEGER NOT NULL ,
​    CONSTRAINT KATEGORIE_PK PRIMARY KEY CLUSTERED (id)
​WITH
​  (
​    ALLOW_PAGE_LOCKS = ON ,
​    ALLOW_ROW_LOCKS  = ON
​  )
​  ON "default"
​  )
​  ON "default"
​GO

So far I have this: \s*CREATE\s*TABLE\s*(.*)\s*\(\s*(.*\s*) ; but this wont work, because there is always different number of attributes, I need to get all of them and end when word "WITH" or ')' shows up. Thanks for any help.

Upvotes: 1

Views: 140

Answers (1)

6972Honza
6972Honza

Reputation: 33

I figured it out, thanks for help. I edited regex, for taking anything before ',' and i iterate through it, then i get last line.

Upvotes: 1

Related Questions