php regex匹配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)谢谢
发布于 2013-07-30 19:46:12
/([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), ..https://stackoverflow.com/questions/17955744
复制相似问题