0

php正则表达式匹配mysql数据类型,使用所有mysql数据类型作为主题,即

int(5)
varchar(10)
enum('yes', 'no')

我需要这样的数组:

array( 'int', 5 )
array( 'varchar', 10 )
array( 'enum', 'yes', 'no' )    or    array ('enum', array('yes', 'no'))

到目前为止,我可以将括号的内容与:

/\(([^)]+)\)$/   and with    /\((.*)?\)/

都说我需要:

number 1 - everything before the first opening parentheses

number 2 - everything inside the parentheses pair but not matching the parenthesis

number 3 - match the contents of the enum data type and return it's individual values (when values are delimited by "'" or by '"' or not delimited at all)

谢谢

4

1 回答 1

3
/([a-zA-Z\s]*)\((.*)\)$/

([a-zA-Z\s]*)- 匹配零个或多个字母或空格

( - 匹配左括号 (.*) - 匹配任何字符串 )$ - 匹配行尾的右括号

PHP:

preg_match ('/([a-zA-Z\s]*)\((.*)\)$/', $your_string, $matches);
$matches[1] -> Type int, enum, etc.
$matches[2] -> Size 10, (yes, no), ..
于 2013-07-30T19:46:12.783 回答