简体   繁体   English

需要帮助建立正则表达式

[英]Need help building regular expression

I'm trying to build a regular expression to filter out some parts of SQL statements. 我试图建立一个正则表达式来过滤掉SQL语句的某些部分。 The statement I currently work with: 我目前使用的语句:

CREATE TABLE tblname ( 
   column Nr PRIMARY KEY,
   column2 TEXT DEFAULT 'foo',
   column3 TEXT DEFAULT 'foo,bar'
)

I want to extract the column definitions from that statement, like this: 我想从该语句中提取列定义,如下所示:

   column Nr PRIMARY KEY
   column2 TEXT DEFAULT 'foo'
   column3 TEXT DEFAULT 'foo,bar'

What I have so far (JavaScript) to remove the CREATE part and the last bracket: 我到目前为止(JavaScript)删除了CREATE部分和最后一个括号:

sql.replace( /^[\w\s]+\(\s+/, "" ).replace( /\s+\)$/, "" );

I can't split() the string at the comma ocurrences because that's one of the DEFAULT values. 我无法在逗号出现时对字符串进行split() ,因为这是DEFAULT值之一。

Any suggestions? 有什么建议么?

干得好

sql.replace(/^([\w\s]*\()/im, '').replace(/(\)[\w\s]*)$/im, '')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM